Tiny docstring fix in org-footnote.el
[org-mode/org-jambu.git] / lisp / org-exp.el
blob3e843146f9e3d7b7d38c48e7019c37c51b9eb1a5
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.5
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-as-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-table-remove-empty-lines t
564 "Remove empty lines when exporting tables.
565 This is the global equivalent of the :remove-nil-lines option
566 when locally sending a table with #+ORGTBL."
567 :group 'org-export-tables
568 :type 'boolean)
570 (defcustom org-export-prefer-native-exporter-for-tables nil
571 "Non-nil means always export tables created with table.el natively.
572 Natively means use the HTML code generator in table.el.
573 When nil, Org-mode's own HTML generator is used when possible (i.e. if
574 the table does not use row- or column-spanning). This has the
575 advantage, that the automatic HTML conversions for math symbols and
576 sub/superscripts can be applied. Org-mode's HTML generator is also
577 much faster. The LaTeX exporter always use the native exporter for
578 table.el tables."
579 :group 'org-export-tables
580 :type 'boolean)
582 ;;;; Exporting
584 ;;; Variables, constants, and parameter plists
586 (defconst org-level-max 20)
588 (defvar org-export-current-backend nil
589 "During export, this will be bound to a symbol such as 'html,
590 'latex, 'docbook, 'ascii, etc, indicating which of the export
591 backends is in use. Otherwise it has the value nil. Users
592 should not attempt to change the value of this variable
593 directly, but it can be used in code to test whether export is
594 in progress, and if so, what the backend is.")
596 (defvar org-current-export-file nil) ; dynamically scoped parameter
597 (defvar org-current-export-dir nil) ; dynamically scoped parameter
598 (defvar org-export-opt-plist nil
599 "Contains the current option plist.")
600 (defvar org-last-level nil) ; dynamically scoped variable
601 (defvar org-min-level nil) ; dynamically scoped variable
602 (defvar org-levels-open nil) ; dynamically scoped parameter
604 (defconst org-export-plist-vars
605 '((:link-up nil org-export-html-link-up)
606 (:link-home nil org-export-html-link-home)
607 (:language nil org-export-default-language)
608 (:keywords nil org-export-page-keywords)
609 (:description nil org-export-page-description)
610 (:customtime nil org-display-custom-times)
611 (:headline-levels "H" org-export-headline-levels)
612 (:section-numbers "num" org-export-with-section-numbers)
613 (:section-number-format nil org-export-section-number-format)
614 (:table-of-contents "toc" org-export-with-toc)
615 (:preserve-breaks "\\n" org-export-preserve-breaks)
616 (:archived-trees nil org-export-with-archived-trees)
617 (:emphasize "*" org-export-with-emphasize)
618 (:sub-superscript "^" org-export-with-sub-superscripts)
619 (:special-strings "-" org-export-with-special-strings)
620 (:footnotes "f" org-export-with-footnotes)
621 (:drawers "d" org-export-with-drawers)
622 (:tags "tags" org-export-with-tags)
623 (:todo-keywords "todo" org-export-with-todo-keywords)
624 (:priority "pri" org-export-with-priority)
625 (:TeX-macros "TeX" org-export-with-TeX-macros)
626 (:LaTeX-fragments "LaTeX" org-export-with-LaTeX-fragments)
627 (:latex-listings nil org-export-latex-listings)
628 (:skip-before-1st-heading "skip" org-export-skip-text-before-1st-heading)
629 (:fixed-width ":" org-export-with-fixed-width)
630 (:timestamps "<" org-export-with-timestamps)
631 (:author nil user-full-name)
632 (:email nil user-mail-address)
633 (:author-info "author" org-export-author-info)
634 (:email-info "email" org-export-email-info)
635 (:creator-info "creator" org-export-creator-info)
636 (:time-stamp-file "timestamp" org-export-time-stamp-file)
637 (:tables "|" org-export-with-tables)
638 (:table-auto-headline nil org-export-highlight-first-table-line)
639 (:style-include-default nil org-export-html-style-include-default)
640 (:style-include-scripts nil org-export-html-style-include-scripts)
641 (:style nil org-export-html-style)
642 (:style-extra nil org-export-html-style-extra)
643 (:agenda-style nil org-agenda-export-html-style)
644 (:convert-org-links nil org-export-html-link-org-files-as-html)
645 (:inline-images nil org-export-html-inline-images)
646 (:html-extension nil org-export-html-extension)
647 (:html-preamble nil org-export-html-preamble)
648 (:html-postamble nil org-export-html-postamble)
649 (:xml-declaration nil org-export-html-xml-declaration)
650 (:html-table-tag nil org-export-html-table-tag)
651 (:expand-quoted-html "@" org-export-html-expand)
652 (:timestamp nil org-export-html-with-timestamp)
653 (:publishing-directory nil org-export-publishing-directory)
654 (:select-tags nil org-export-select-tags)
655 (:exclude-tags nil org-export-exclude-tags)
657 (:latex-image-options nil org-export-latex-image-default-option))
658 "List of properties that represent export/publishing variables.
659 Each element is a list of 3 items:
660 1. The property that is used internally, and also for org-publish-project-alist
661 2. The string that can be used in the OPTION lines to set this option,
662 or nil if this option cannot be changed in this way
663 3. The customization variable that sets the default for this option."
666 (defun org-default-export-plist ()
667 "Return the property list with default settings for the export variables."
668 (let* ((infile (org-infile-export-plist))
669 (letbind (plist-get infile :let-bind))
670 (l org-export-plist-vars) rtn e s v)
671 (while (setq e (pop l))
672 (setq s (nth 2 e)
673 v (cond
674 ((assq s letbind) (nth 1 (assq s letbind)))
675 ((boundp s) (symbol-value s))
676 (t nil))
677 rtn (cons (car e) (cons v rtn))))
678 rtn))
680 (defvar org-export-inbuffer-options-extra nil
681 "List of additional in-buffer options that should be detected.
682 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
683 etc. Extensions can add to this list to get their options detected, and they
684 can then add a function to `org-export-options-filters' to process these
685 options.
686 Each element in this list must be a list, with the in-buffer keyword as car,
687 and a property (a symbol) as the next element. All occurrences of the
688 keyword will be found, the values concatenated with a space character
689 in between, and the result stored in the export options property list.")
691 (defvar org-export-options-filters nil
692 "Functions to be called to finalize the export/publishing options.
693 All these options are stored in a property list, and each of the functions
694 in this hook gets a chance to modify this property list. Each function
695 must accept the property list as an argument, and must return the (possibly
696 modified) list.")
698 ;; FIXME: should we fold case here?
699 (defun org-infile-export-plist ()
700 "Return the property list with file-local settings for export."
701 (save-excursion
702 (save-restriction
703 (widen)
704 (goto-char (point-min))
705 (let ((re (org-make-options-regexp
706 (append
707 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
708 "MATHJAX"
709 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE"
710 "LATEX_HEADER" "LATEX_CLASS"
711 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS"
712 "KEYWORDS" "DESCRIPTION" "MACRO" "BIND" "XSLT")
713 (mapcar 'car org-export-inbuffer-options-extra))))
714 (case-fold-search t)
715 p key val text options mathjax a pr style
716 latex-header latex-class macros letbind
717 ext-setup-or-nil setup-contents (start 0))
718 (while (or (and ext-setup-or-nil
719 (string-match re ext-setup-or-nil start)
720 (setq start (match-end 0)))
721 (and (setq ext-setup-or-nil nil start 0)
722 (re-search-forward re nil t)))
723 (setq key (upcase (org-match-string-no-properties 1 ext-setup-or-nil))
724 val (org-match-string-no-properties 2 ext-setup-or-nil))
725 (cond
726 ((setq a (assoc key org-export-inbuffer-options-extra))
727 (setq pr (nth 1 a))
728 (setq p (plist-put p pr (concat (plist-get p pr) " " val))))
729 ((string-equal key "TITLE") (setq p (plist-put p :title val)))
730 ((string-equal key "AUTHOR")(setq p (plist-put p :author val)))
731 ((string-equal key "EMAIL") (setq p (plist-put p :email val)))
732 ((string-equal key "DATE") (setq p (plist-put p :date val)))
733 ((string-equal key "KEYWORDS") (setq p (plist-put p :keywords val)))
734 ((string-equal key "DESCRIPTION")
735 (setq p (plist-put p :description val)))
736 ((string-equal key "LANGUAGE") (setq p (plist-put p :language val)))
737 ((string-equal key "STYLE")
738 (setq style (concat style "\n" val)))
739 ((string-equal key "LATEX_HEADER")
740 (setq latex-header (concat latex-header "\n" val)))
741 ((string-equal key "LATEX_CLASS")
742 (setq latex-class val))
743 ((string-equal key "TEXT")
744 (setq text (if text (concat text "\n" val) val)))
745 ((string-equal key "OPTIONS")
746 (setq options (concat val " " options)))
747 ((string-equal key "MATHJAX")
748 (setq mathjax (concat val " " mathjax)))
749 ((string-equal key "BIND")
750 (push (read (concat "(" val ")")) letbind))
751 ((string-equal key "XSLT")
752 (setq p (plist-put p :xslt val)))
753 ((string-equal key "LINK_UP")
754 (setq p (plist-put p :link-up val)))
755 ((string-equal key "LINK_HOME")
756 (setq p (plist-put p :link-home val)))
757 ((string-equal key "EXPORT_SELECT_TAGS")
758 (setq p (plist-put p :select-tags (org-split-string val))))
759 ((string-equal key "EXPORT_EXCLUDE_TAGS")
760 (setq p (plist-put p :exclude-tags (org-split-string val))))
761 ((string-equal key "MACRO")
762 (push val macros))
763 ((equal key "SETUPFILE")
764 (setq setup-contents (org-file-contents
765 (expand-file-name
766 (org-remove-double-quotes
767 (org-trim val)))
768 'noerror))
769 (if (not ext-setup-or-nil)
770 (setq ext-setup-or-nil setup-contents start 0)
771 (setq ext-setup-or-nil
772 (concat (substring ext-setup-or-nil 0 start)
773 "\n" setup-contents "\n"
774 (substring ext-setup-or-nil start)))))))
775 (setq p (plist-put p :text text))
776 (when (and letbind (org-export-confirm-letbind))
777 (setq p (plist-put p :let-bind letbind)))
778 (when style (setq p (plist-put p :style-extra style)))
779 (when latex-header
780 (setq p (plist-put p :latex-header-extra (substring latex-header 1))))
781 (when latex-class
782 (setq p (plist-put p :latex-class latex-class)))
783 (when options
784 (setq p (org-export-add-options-to-plist p options)))
785 (when mathjax
786 (setq p (plist-put p :mathjax mathjax)))
787 ;; Add macro definitions
788 (setq p (plist-put p :macro-date "(eval (format-time-string \"$1\"))"))
789 (setq p (plist-put p :macro-time "(eval (format-time-string \"$1\"))"))
790 (setq p (plist-put p :macro-property "(eval (org-entry-get nil \"$1\" 'selective))"))
791 (setq p (plist-put
792 p :macro-modification-time
793 (and (buffer-file-name)
794 (file-exists-p (buffer-file-name))
795 (concat
796 "(eval (format-time-string \"$1\" '"
797 (prin1-to-string (nth 5 (file-attributes
798 (buffer-file-name))))
799 "))"))))
800 (setq p (plist-put p :macro-input-file (and (buffer-file-name)
801 (file-name-nondirectory
802 (buffer-file-name)))))
803 (while (setq val (pop macros))
804 (when (string-match "^\\([-a-zA-Z0-9_]+\\)[ \t]+\\(.*?[ \t]*$\\)" val)
805 (setq p (plist-put
806 p (intern
807 (concat ":macro-" (downcase (match-string 1 val))))
808 (org-export-interpolate-newlines (match-string 2 val))))))
809 p))))
811 (defun org-export-interpolate-newlines (s)
812 (while (string-match "\\\\n" s)
813 (setq s (replace-match "\n" t t s)))
816 (defvar org-export-allow-BIND-local nil)
817 (defun org-export-confirm-letbind ()
818 "Can we use #+BIND values during export?
819 By default this will ask for confirmation by the user, to divert possible
820 security risks."
821 (cond
822 ((not org-export-allow-BIND) nil)
823 ((eq org-export-allow-BIND t) t)
824 ((local-variable-p 'org-export-allow-BIND-local (current-buffer))
825 org-export-allow-BIND-local)
826 (t (org-set-local 'org-export-allow-BIND-local
827 (yes-or-no-p "Allow BIND values in this buffer? ")))))
829 (defun org-install-letbind ()
830 "Install the values from #+BIND lines as local variables."
831 (let ((letbind (plist-get org-export-opt-plist :let-bind))
832 pair)
833 (while (setq pair (pop letbind))
834 (org-set-local (car pair) (nth 1 pair)))))
836 (defun org-export-add-options-to-plist (p options)
837 "Parse an OPTIONS line and set values in the property list P."
838 (let (o)
839 (when options
840 (let ((op org-export-plist-vars))
841 (while (setq o (pop op))
842 (if (and (nth 1 o)
843 (string-match (concat "\\<" (regexp-quote (nth 1 o))
844 ":\\([^ \t\n\r;,.]*\\)")
845 options))
846 (setq p (plist-put p (car o)
847 (car (read-from-string
848 (match-string 1 options))))))))))
851 (defun org-export-add-subtree-options (p pos)
852 "Add options in subtree at position POS to property list P."
853 (save-excursion
854 (goto-char pos)
855 (when (org-at-heading-p)
856 (let (a)
857 ;; This is actually read in `org-export-get-title-from-subtree'
858 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
859 ;; (setq p (plist-put p :title a)))
860 (when (setq a (org-entry-get pos "EXPORT_TEXT"))
861 (setq p (plist-put p :text a)))
862 (when (setq a (org-entry-get pos "EXPORT_AUTHOR"))
863 (setq p (plist-put p :author a)))
864 (when (setq a (org-entry-get pos "EXPORT_DATE"))
865 (setq p (plist-put p :date a)))
866 (when (setq a (org-entry-get pos "EXPORT_OPTIONS"))
867 (setq p (org-export-add-options-to-plist p a)))))
870 (defun org-export-directory (type plist)
871 (let* ((val (plist-get plist :publishing-directory))
872 (dir (if (listp val)
873 (or (cdr (assoc type val)) ".")
874 val)))
875 dir))
877 (defun org-export-process-option-filters (plist)
878 (let ((functions org-export-options-filters) f)
879 (while (setq f (pop functions))
880 (setq plist (funcall f plist))))
881 plist)
883 ;;;###autoload
884 (defun org-export (&optional arg)
885 "Export dispatcher for Org-mode.
886 When `org-export-run-in-background' is non-nil, try to run the command
887 in the background. This will be done only for commands that write
888 to a file. For details see the docstring of `org-export-run-in-background'.
890 The prefix argument ARG will be passed to the exporter. However, if
891 ARG is a double universal prefix \\[universal-argument] \\[universal-argument], \
892 that means to inverse the
893 value of `org-export-run-in-background'.
895 If `org-export-initial-scope' is set to 'subtree, try to export
896 the current subtree, otherwise try to export the whole buffer.
897 Pressing `1' will switch between these two options."
898 (interactive "P")
899 (let* ((bg (org-xor (equal arg '(16)) org-export-run-in-background))
900 (subtree-p (or (org-region-active-p)
901 (eq org-export-initial-scope 'subtree)))
902 (help "[t] insert the export option template
903 \[v] limit export to visible part of outline tree
904 \[1] switch buffer/subtree export
905 \[SPC] publish enclosing subtree (with LaTeX_CLASS or EXPORT_FILE_NAME prop)
907 \[a/n/u] export as ASCII/Latin-1/UTF-8 [A/N/U] to temporary buffer
909 \[h] export as HTML [H] to temporary buffer [R] export region
910 \[b] export as HTML and open in browser
912 \[l] export as LaTeX [L] to temporary buffer
913 \[p] export as LaTeX and process to PDF [d] ... and open PDF file
915 \[D] export as DocBook [V] export as DocBook, process to PDF, and open
917 \[j] export as TaskJuggler [J] ... and open
919 \[m] export as Freemind mind map
920 \[x] export as XOXO
921 \[g] export using Wes Hardaker's generic exporter
923 \[i] export current file as iCalendar file
924 \[I] export all agenda files as iCalendar files [c] ...as one combined file
926 \[F] publish current file [P] publish current project
927 \[X] publish a project... [E] publish every projects")
928 (cmds
929 '((?t org-insert-export-options-template nil)
930 (?v org-export-visible nil)
931 (?a org-export-as-ascii t)
932 (?A org-export-as-ascii-to-buffer t)
933 (?n org-export-as-latin1 t)
934 (?N org-export-as-latin1-to-buffer t)
935 (?u org-export-as-utf8 t)
936 (?U org-export-as-utf8-to-buffer t)
937 (?h org-export-as-html t)
938 (?b org-export-as-html-and-open t)
939 (?H org-export-as-html-to-buffer nil)
940 (?R org-export-region-as-html nil)
941 (?x org-export-as-xoxo t)
942 (?g org-export-generic t)
943 (?D org-export-as-docbook t)
944 (?V org-export-as-docbook-pdf-and-open t)
945 (?j org-export-as-taskjuggler t)
946 (?J org-export-as-taskjuggler-and-open t)
947 (?m org-export-as-freemind t)
948 (?l org-export-as-latex t)
949 (?p org-export-as-pdf t)
950 (?d org-export-as-pdf-and-open t)
951 (?L org-export-as-latex-to-buffer nil)
952 (?i org-export-icalendar-this-file t)
953 (?I org-export-icalendar-all-agenda-files t)
954 (?c org-export-icalendar-combine-agenda-files t)
955 (?F org-publish-current-file t)
956 (?P org-publish-current-project t)
957 (?X org-publish t)
958 (?E org-publish-all t)))
959 r1 r2 ass
960 (cpos (point)) (cbuf (current-buffer)) bpos)
961 (save-excursion
962 (save-window-excursion
963 (if subtree-p
964 (message "Export subtree: ")
965 (message "Export buffer: "))
966 (delete-other-windows)
967 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
968 (princ help))
969 (org-fit-window-to-buffer (get-buffer-window
970 "*Org Export/Publishing Help*"))
971 (while (eq (setq r1 (read-char-exclusive)) ?1)
972 (cond (subtree-p
973 (setq subtree-p nil)
974 (message "Export buffer: "))
975 ((not subtree-p)
976 (setq subtree-p t)
977 (message "Export subtree: "))))
978 (when (eq r1 ?\ )
979 (let ((case-fold-search t))
980 (if (re-search-backward
981 "^[ \t]+\\(:latex_class:\\|:export_title:\\)[ \t]+\\S-"
982 nil t)
983 (progn
984 (org-back-to-heading t)
985 (setq subtree-p t)
986 (setq bpos (point))
987 (message "Select command (for subtree): ")
988 (setq r1 (read-char-exclusive)))
989 (error "No enclosing node with LaTeX_CLASS or EXPORT_FILE_NAME")
990 )))))
991 (redisplay)
992 (and bpos (goto-char bpos))
993 (setq r2 (if (< r1 27) (+ r1 96) r1))
994 (unless (setq ass (assq r2 cmds))
995 (error "No command associated with key %c" r1))
996 (if (and bg (nth 2 ass)
997 (not (buffer-base-buffer))
998 (not (org-region-active-p)))
999 ;; execute in background
1000 (let ((p (start-process
1001 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
1002 "*Org Processes*"
1003 (expand-file-name invocation-name invocation-directory)
1004 "-batch"
1005 "-l" user-init-file
1006 "--eval" "(require 'org-exp)"
1007 "--eval" "(setq org-wait .2)"
1008 (buffer-file-name)
1009 "-f" (symbol-name (nth 1 ass)))))
1010 (set-process-sentinel p 'org-export-process-sentinel)
1011 (message "Background process \"%s\": started" p))
1012 ;; background processing not requested, or not possible
1013 (if subtree-p (progn (org-mark-subtree) (activate-mark)))
1014 (call-interactively (nth 1 ass))
1015 (when (and bpos (get-buffer-window cbuf))
1016 (let ((cw (selected-window)))
1017 (select-window (get-buffer-window cbuf))
1018 (goto-char cpos)
1019 (deactivate-mark)
1020 (select-window cw))))))
1022 (defun org-export-process-sentinel (process status)
1023 (if (string-match "\n+\\'" status)
1024 (setq status (substring status 0 -1)))
1025 (message "Background process \"%s\": %s" process status))
1027 ;;; General functions for all backends
1029 (defvar org-export-target-aliases nil
1030 "Alist of targets with invisible aliases.")
1031 (defvar org-export-preferred-target-alist nil
1032 "Alist of section id's with preferred aliases.")
1033 (defvar org-export-id-target-alist nil
1034 "Alist of section id's with preferred aliases.")
1035 (defvar org-export-code-refs nil
1036 "Alist of code references and line numbers.")
1038 (defun org-export-preprocess-string (string &rest parameters)
1039 "Cleanup STRING so that the true exported has a more consistent source.
1040 This function takes STRING, which should be a buffer-string of an org-file
1041 to export. It then creates a temporary buffer where it does its job.
1042 The result is then again returned as a string, and the exporter works
1043 on this string to produce the exported version."
1044 (interactive)
1045 (let* ((org-export-current-backend (plist-get parameters :for-backend))
1046 (archived-trees (plist-get parameters :archived-trees))
1047 (inhibit-read-only t)
1048 (drawers org-drawers)
1049 (outline-regexp "\\*+ ")
1050 (source-buffer (current-buffer))
1051 target-alist rtn)
1053 (setq org-export-target-aliases nil
1054 org-export-preferred-target-alist nil
1055 org-export-id-target-alist nil
1056 org-export-code-refs nil)
1058 (with-current-buffer (get-buffer-create " org-mode-tmp")
1059 (erase-buffer)
1060 (insert string)
1061 (setq case-fold-search t)
1063 (let ((inhibit-read-only t))
1064 (remove-text-properties (point-min) (point-max)
1065 '(read-only t)))
1067 ;; Remove license-to-kill stuff
1068 ;; The caller marks some stuff for killing, stuff that has been
1069 ;; used to create the page title, for example.
1070 (org-export-kill-licensed-text)
1072 (let ((org-inhibit-startup t)) (org-mode))
1073 (setq case-fold-search t)
1074 (org-clone-local-variables source-buffer "^\\(org-\\|orgtbl-\\)")
1075 (org-install-letbind)
1077 ;; Call the hook
1078 (run-hooks 'org-export-preprocess-hook)
1080 ;; Process the macros
1081 (org-export-preprocess-apply-macros)
1082 (run-hooks 'org-export-preprocess-after-macros-hook)
1084 (untabify (point-min) (point-max))
1086 ;; Handle include files, and call a hook
1087 (org-export-handle-include-files-recurse)
1088 (run-hooks 'org-export-preprocess-after-include-files-hook)
1090 ;; Get rid of archived trees
1091 (org-export-remove-archived-trees archived-trees)
1093 ;; Remove comment environment and comment subtrees
1094 (org-export-remove-comment-blocks-and-subtrees)
1096 ;; Get rid of excluded trees, and call a hook
1097 (org-export-handle-export-tags (plist-get parameters :select-tags)
1098 (plist-get parameters :exclude-tags))
1099 (run-hooks 'org-export-preprocess-after-tree-selection-hook)
1101 ;; Change lists ending. Other parts of export may insert blank
1102 ;; lines and lists' structure could be altered.
1103 (org-export-mark-list-end)
1105 ;; Export code blocks
1106 (org-export-blocks-preprocess)
1108 ;; Mark lists with properties
1109 (org-export-mark-list-properties)
1111 ;; Handle source code snippets
1112 (org-export-replace-src-segments-and-examples)
1114 ;; Protect short examples marked by a leading colon
1115 (org-export-protect-colon-examples)
1117 ;; Protected spaces
1118 (org-export-convert-protected-spaces)
1120 ;; Normalize footnotes
1121 (when (plist-get parameters :footnotes)
1122 (org-footnote-normalize nil t))
1124 ;; Find all headings and compute the targets for them
1125 (setq target-alist (org-export-define-heading-targets target-alist))
1127 (run-hooks 'org-export-preprocess-after-headline-targets-hook)
1129 ;; Find HTML special classes for headlines
1130 (org-export-remember-html-container-classes)
1132 ;; Get rid of drawers
1133 (org-export-remove-or-extract-drawers
1134 drawers (plist-get parameters :drawers))
1136 ;; Get the correct stuff before the first headline
1137 (when (plist-get parameters :skip-before-1st-heading)
1138 (goto-char (point-min))
1139 (when (re-search-forward "^\\(#.*\n\\)?\\*+[ \t]" nil t)
1140 (delete-region (point-min) (match-beginning 0))
1141 (goto-char (point-min))
1142 (insert "\n")))
1143 (when (plist-get parameters :add-text)
1144 (goto-char (point-min))
1145 (insert (plist-get parameters :add-text) "\n"))
1147 ;; Remove todo-keywords before exporting, if the user has requested so
1148 (org-export-remove-headline-metadata parameters)
1150 ;; Find targets in comments and move them out of comments,
1151 ;; but mark them as targets that should be invisible
1152 (setq target-alist (org-export-handle-invisible-targets target-alist))
1154 ;; Select and protect backend specific stuff, throw away stuff
1155 ;; that is specific for other backends
1156 (run-hooks 'org-export-preprocess-before-selecting-backend-code-hook)
1157 (org-export-select-backend-specific-text)
1159 ;; Protect quoted subtrees
1160 (org-export-protect-quoted-subtrees)
1162 ;; Remove clock lines
1163 (org-export-remove-clock-lines)
1165 ;; Protect verbatim elements
1166 (org-export-protect-verbatim)
1168 ;; Blockquotes, verse, and center
1169 (org-export-mark-blockquote-verse-center)
1170 (run-hooks 'org-export-preprocess-after-blockquote-hook)
1172 ;; Remove timestamps, if the user has requested so
1173 (unless (plist-get parameters :timestamps)
1174 (org-export-remove-timestamps))
1176 ;; Attach captions to the correct object
1177 (setq target-alist (org-export-attach-captions-and-attributes target-alist))
1179 ;; Find matches for radio targets and turn them into internal links
1180 (org-export-mark-radio-links)
1181 (run-hooks 'org-export-preprocess-after-radio-targets-hook)
1183 ;; Find all links that contain a newline and put them into a single line
1184 (org-export-concatenate-multiline-links)
1186 ;; Normalize links: Convert angle and plain links into bracket links
1187 ;; and expand link abbreviations
1188 (run-hooks 'org-export-preprocess-before-normalizing-links-hook)
1189 (org-export-normalize-links)
1191 ;; Find all internal links. If they have a fuzzy match (i.e. not
1192 ;; a *dedicated* target match, let the link point to the
1193 ;; corresponding section.
1194 (org-export-target-internal-links target-alist)
1196 ;; Find multiline emphasis and put them into single line
1197 (when (plist-get parameters :emph-multiline)
1198 (org-export-concatenate-multiline-emphasis))
1200 ;; Remove special table lines, and store alignment information
1201 (org-store-forced-table-alignment)
1202 (when org-export-table-remove-special-lines
1203 (org-export-remove-special-table-lines))
1205 ;; Another hook
1206 (run-hooks 'org-export-preprocess-before-backend-specifics-hook)
1208 ;; Backend-specific preprocessing
1209 (let* ((backend-name (symbol-name org-export-current-backend))
1210 (f (intern (format "org-export-%s-preprocess" backend-name))))
1211 (require (intern (concat "org-" backend-name)) nil)
1212 (funcall f parameters))
1214 ;; Remove or replace comments
1215 (org-export-handle-comments (plist-get parameters :comments))
1217 ;; Remove #+TBLFM and #+TBLNAME lines
1218 (org-export-handle-table-metalines)
1220 ;; Run the final hook
1221 (run-hooks 'org-export-preprocess-final-hook)
1223 (setq rtn (buffer-string)))
1224 (kill-buffer " org-mode-tmp")
1225 rtn))
1227 (defun org-export-kill-licensed-text ()
1228 "Remove all text that is marked with a :org-license-to-kill property."
1229 (let (p)
1230 (while (setq p (text-property-any (point-min) (point-max)
1231 :org-license-to-kill t))
1232 (delete-region
1233 p (or (next-single-property-change p :org-license-to-kill)
1234 (point-max))))))
1236 (defvar org-export-define-heading-targets-headline-hook nil
1237 "Hook that is run when a headline was matched during target search.
1238 This is part of the preprocessing for export.")
1240 (defun org-export-define-heading-targets (target-alist)
1241 "Find all headings and define the targets for them.
1242 The new targets are added to TARGET-ALIST, which is also returned.
1243 Also find all ID and CUSTOM_ID properties and store them."
1244 (goto-char (point-min))
1245 (org-init-section-numbers)
1246 (let ((re (concat "^" org-outline-regexp
1247 "\\|"
1248 "^[ \t]*:\\(ID\\|CUSTOM_ID\\):[ \t]*\\([^ \t\r\n]+\\)"))
1249 level target last-section-target a id)
1250 (while (re-search-forward re nil t)
1251 (org-if-unprotected-at (match-beginning 0)
1252 (if (match-end 2)
1253 (progn
1254 (setq id (org-match-string-no-properties 2))
1255 (push (cons id target) target-alist)
1256 (setq a (or (assoc last-section-target org-export-target-aliases)
1257 (progn
1258 (push (list last-section-target)
1259 org-export-target-aliases)
1260 (car org-export-target-aliases))))
1261 (push (caar target-alist) (cdr a))
1262 (when (equal (match-string 1) "CUSTOM_ID")
1263 (if (not (assoc last-section-target
1264 org-export-preferred-target-alist))
1265 (push (cons last-section-target id)
1266 org-export-preferred-target-alist)))
1267 (when (equal (match-string 1) "ID")
1268 (if (not (assoc last-section-target
1269 org-export-id-target-alist))
1270 (push (cons last-section-target (concat "ID-" id))
1271 org-export-id-target-alist))))
1272 (setq level (org-reduced-level
1273 (save-excursion (goto-char (point-at-bol))
1274 (org-outline-level))))
1275 (setq target (org-solidify-link-text
1276 (format "sec-%s" (replace-regexp-in-string
1277 "\\." "_"
1278 (org-section-number level)))))
1279 (setq last-section-target target)
1280 (push (cons target target) target-alist)
1281 (add-text-properties
1282 (point-at-bol) (point-at-eol)
1283 (list 'target target))
1284 (run-hooks 'org-export-define-heading-targets-headline-hook)))))
1285 target-alist)
1287 (defun org-export-handle-invisible-targets (target-alist)
1288 "Find targets in comments and move them out of comments.
1289 Mark them as invisible targets."
1290 (let (target tmp a)
1291 (goto-char (point-min))
1292 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t)
1293 ;; Check if the line before or after is a headline with a target
1294 (if (setq target (or (get-text-property (point-at-bol 0) 'target)
1295 (get-text-property (point-at-bol 2) 'target)))
1296 (progn
1297 ;; use the existing target in a neighboring line
1298 (setq tmp (match-string 2))
1299 (replace-match "")
1300 (and (looking-at "\n") (delete-char 1))
1301 (push (cons (setq tmp (org-solidify-link-text tmp)) target)
1302 target-alist)
1303 (setq a (or (assoc target org-export-target-aliases)
1304 (progn
1305 (push (list target) org-export-target-aliases)
1306 (car org-export-target-aliases))))
1307 (push tmp (cdr a)))
1308 ;; Make an invisible target
1309 (replace-match "\\1(INVISIBLE)"))))
1310 target-alist)
1312 (defun org-export-target-internal-links (target-alist)
1313 "Find all internal links and assign targets to them.
1314 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1315 let the link point to the corresponding section.
1316 This function also handles the id links, if they have a match in
1317 the current file."
1318 (goto-char (point-min))
1319 (while (re-search-forward org-bracket-link-regexp nil t)
1320 (org-if-unprotected-at (1+ (match-beginning 0))
1321 (let* ((org-link-search-must-match-exact-headline t)
1322 (md (match-data))
1323 (desc (match-end 2))
1324 (link (org-link-unescape (match-string 1)))
1325 (slink (org-solidify-link-text link))
1326 found props pos cref
1327 (target
1328 (cond
1329 ((= (string-to-char link) ?#)
1330 ;; user wants exactly this link
1331 link)
1332 ((cdr (assoc slink target-alist))
1333 (or (cdr (assoc (assoc slink target-alist)
1334 org-export-preferred-target-alist))
1335 (cdr (assoc slink target-alist))))
1336 ((and (string-match "^id:" link)
1337 (cdr (assoc (substring link 3) target-alist))))
1338 ((string-match "^(\\(.*\\))$" link)
1339 (setq cref (match-string 1 link))
1340 (concat "coderef:" cref))
1341 ((string-match org-link-types-re link) nil)
1342 ((or (file-name-absolute-p link)
1343 (string-match "^\\." link))
1344 nil)
1346 (let ((org-link-search-inhibit-query t))
1347 (save-excursion
1348 (setq found (condition-case nil (org-link-search link)
1349 (error nil)))
1350 (when (and found
1351 (or (org-on-heading-p)
1352 (not (eq found 'dedicated))))
1353 (or (get-text-property (point) 'target)
1354 (get-text-property
1355 (max (point-min)
1356 (1- (or (previous-single-property-change
1357 (point) 'target) 0)))
1358 'target)))))))))
1359 (when target
1360 (set-match-data md)
1361 (goto-char (match-beginning 1))
1362 (setq props (text-properties-at (point)))
1363 (delete-region (match-beginning 1) (match-end 1))
1364 (setq pos (point))
1365 (insert target)
1366 (unless desc (insert "][" link))
1367 (add-text-properties pos (point) props))))))
1369 (defun org-export-remember-html-container-classes ()
1370 "Store the HTML_CONTAINER_CLASS properties in a text property."
1371 (goto-char (point-min))
1372 (let (class)
1373 (while (re-search-forward
1374 "^[ \t]*:HTML_CONTAINER_CLASS:[ \t]+\\(.+\\)$" nil t)
1375 (setq class (match-string 1))
1376 (save-excursion
1377 (org-back-to-heading t)
1378 (put-text-property (point-at-bol) (point-at-eol) 'html-container-class class)))))
1380 (defvar org-export-format-drawer-function nil
1381 "Function to be called to format the contents of a drawer.
1382 The function must accept three parameters:
1383 NAME the drawer name, like \"PROPERTIES\"
1384 CONTENT the content of the drawer.
1385 You can check the export backend through `org-export-current-backend'.
1386 The function should return the text to be inserted into the buffer.
1387 If this is nil, `org-export-format-drawer' is used as a default.")
1389 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers)
1390 "Remove drawers, or extract and format the content.
1391 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1392 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1393 whose content to keep. Any drawers that are in ALL-DRAWERS but not in
1394 EXP-DRAWERS will be removed."
1395 (goto-char (point-min))
1396 (let ((re (concat "^[ \t]*:\\("
1397 (mapconcat 'identity all-drawers "\\|")
1398 "\\):[ \t]*$"))
1399 name beg beg-content eol content)
1400 (while (re-search-forward re nil t)
1401 (org-if-unprotected
1402 (setq name (match-string 1))
1403 (setq beg (match-beginning 0)
1404 beg-content (1+ (point-at-eol))
1405 eol (point-at-eol))
1406 (if (not (and (re-search-forward
1407 "^\\([ \t]*:END:[ \t]*\n?\\)\\|^\\*+[ \t]" nil t)
1408 (match-end 1)))
1409 (goto-char eol)
1410 (goto-char (match-beginning 0))
1411 (and (looking-at ".*\n?") (replace-match ""))
1412 (setq content (buffer-substring beg-content (point)))
1413 (delete-region beg (point))
1414 (when (or (eq exp-drawers t)
1415 (member name exp-drawers))
1416 (setq content (funcall (or org-export-format-drawer-function
1417 'org-export-format-drawer)
1418 name content))
1419 (insert content)))))))
1421 (defun org-export-format-drawer (name content)
1422 "Format the content of a drawer as a colon example."
1423 (if (string-match "[ \t]+\\'" content)
1424 (setq content (substring content (match-beginning 0))))
1425 (while (string-match "\\`[ \t]*\n" content)
1426 (setq content (substring content (match-end 0))))
1427 (setq content (org-remove-indentation content))
1428 (setq content (concat ": " (mapconcat 'identity
1429 (org-split-string content "\n")
1430 "\n: ")
1431 "\n"))
1432 (setq content (concat " : " (upcase name) "\n" content))
1433 (org-add-props content nil 'org-protected t))
1435 (defun org-export-handle-export-tags (select-tags exclude-tags)
1436 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1437 Both arguments are lists of tags.
1438 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1439 will be removed.
1440 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1441 removed as well."
1442 (remove-text-properties (point-min) (point-max) '(:org-delete t))
1443 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1444 select-tags "\\|")
1445 "\\):"))
1446 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1447 exclude-tags "\\|")
1448 "\\):"))
1449 beg end cont)
1450 (goto-char (point-min))
1451 (when (and select-tags
1452 (re-search-forward
1453 (concat "^\\*+[ \t].*" re-sel "[^ \t\n]*[ \t]*$") nil t))
1454 ;; At least one tree is marked for export, this means
1455 ;; all the unmarked stuff needs to go.
1456 ;; Dig out the trees that should be exported
1457 (goto-char (point-min))
1458 (outline-next-heading)
1459 (setq beg (point))
1460 (put-text-property beg (point-max) :org-delete t)
1461 (while (re-search-forward re-sel nil t)
1462 (when (org-on-heading-p)
1463 (org-back-to-heading)
1464 (remove-text-properties
1465 (max (1- (point)) (point-min))
1466 (setq cont (save-excursion (org-end-of-subtree t t)))
1467 '(:org-delete t))
1468 (while (and (org-up-heading-safe)
1469 (get-text-property (point) :org-delete))
1470 (remove-text-properties (max (1- (point)) (point-min))
1471 (point-at-eol) '(:org-delete t)))
1472 (goto-char cont))))
1473 ;; Remove the trees explicitly marked for noexport
1474 (when exclude-tags
1475 (goto-char (point-min))
1476 (while (re-search-forward re-excl nil t)
1477 (when (org-at-heading-p)
1478 (org-back-to-heading t)
1479 (setq beg (point))
1480 (org-end-of-subtree t t)
1481 (delete-region beg (point))
1482 (when (featurep 'org-inlinetask)
1483 (org-inlinetask-remove-END-maybe)))))
1484 ;; Remove everything that is now still marked for deletion
1485 (goto-char (point-min))
1486 (while (setq beg (text-property-any (point-min) (point-max) :org-delete t))
1487 (setq end (or (next-single-property-change beg :org-delete)
1488 (point-max)))
1489 (delete-region beg end))))
1491 (defun org-export-remove-archived-trees (export-archived-trees)
1492 "Remove archived trees.
1493 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1494 When it is t, the entire archived tree will be exported.
1495 When it is nil the entire tree including the headline will be removed
1496 from the buffer."
1497 (let ((re-archive (concat ":" org-archive-tag ":"))
1498 a b)
1499 (when (not (eq export-archived-trees t))
1500 (goto-char (point-min))
1501 (while (re-search-forward re-archive nil t)
1502 (if (not (org-on-heading-p t))
1503 (goto-char (point-at-eol))
1504 (beginning-of-line 1)
1505 (setq a (if export-archived-trees
1506 (1+ (point-at-eol)) (point))
1507 b (org-end-of-subtree t))
1508 (if (> b a) (delete-region a b)))))))
1510 (defun org-export-remove-headline-metadata (opts)
1511 "Remove meta data from the headline, according to user options."
1512 (let ((re org-complex-heading-regexp)
1513 (todo (plist-get opts :todo-keywords))
1514 (tags (plist-get opts :tags))
1515 (pri (plist-get opts :priority))
1516 (elts '(1 2 3 4 5))
1517 (case-fold-search nil)
1518 rpl)
1519 (setq elts (delq nil (list 1 (if todo 2) (if pri 3) 4 (if tags 5))))
1520 (when (or (not todo) (not tags) (not pri))
1521 (goto-char (point-min))
1522 (while (re-search-forward re nil t)
1523 (org-if-unprotected
1524 (setq rpl (mapconcat (lambda (i) (if (match-end i) (match-string i) ""))
1525 elts " "))
1526 (replace-match rpl t t))))))
1528 (defun org-export-remove-timestamps ()
1529 "Remove timestamps and keywords for export."
1530 (goto-char (point-min))
1531 (while (re-search-forward org-maybe-keyword-time-regexp nil t)
1532 (backward-char 1)
1533 (org-if-unprotected
1534 (unless (save-match-data (org-at-table-p))
1535 (replace-match "")
1536 (beginning-of-line 1)
1537 (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
1538 (replace-match ""))))))
1540 (defun org-export-remove-clock-lines ()
1541 "Remove clock lines for export."
1542 (goto-char (point-min))
1543 (let ((re (concat "^[ \t]*" org-clock-string ".*\n?")))
1544 (while (re-search-forward re nil t)
1545 (org-if-unprotected
1546 (replace-match "")))))
1548 (defun org-export-protect-quoted-subtrees ()
1549 "Mark quoted subtrees with the protection property."
1550 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string "\\>")))
1551 (goto-char (point-min))
1552 (while (re-search-forward re-quote nil t)
1553 (goto-char (match-beginning 0))
1554 (end-of-line 1)
1555 (add-text-properties (point) (org-end-of-subtree t)
1556 '(org-protected t)))))
1558 (defun org-export-convert-protected-spaces ()
1559 "Convert strings like \\____ to protected spaces in all backends."
1560 (goto-char (point-min))
1561 (while (re-search-forward "\\\\__+" nil t)
1562 (org-if-unprotected-1
1563 (replace-match
1564 (org-add-props
1565 (cond
1566 ((eq org-export-current-backend 'latex)
1567 (format "\\hspace{%dex}" (- (match-end 0) (match-beginning 0))))
1568 ((eq org-export-current-backend 'html)
1569 (org-add-props (match-string 0) nil
1570 'org-whitespace (- (match-end 0) (match-beginning 0))))
1571 ;; ((eq org-export-current-backend 'docbook))
1572 ((eq org-export-current-backend 'ascii)
1573 (org-add-props (match-string 0) '(org-whitespace t)))
1574 (t (make-string (- (match-end 0) (match-beginning 0)) ?\ )))
1575 '(org-protected t))
1576 t t))))
1578 (defun org-export-protect-verbatim ()
1579 "Mark verbatim snippets with the protection property."
1580 (goto-char (point-min))
1581 (while (re-search-forward org-verbatim-re nil t)
1582 (org-if-unprotected
1583 (add-text-properties (match-beginning 4) (match-end 4)
1584 '(org-protected t org-verbatim-emph t))
1585 (goto-char (1+ (match-end 4))))))
1587 (defun org-export-protect-colon-examples ()
1588 "Protect lines starting with a colon."
1589 (goto-char (point-min))
1590 (let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg)
1591 (while (re-search-forward re nil t)
1592 (beginning-of-line 1)
1593 (setq beg (point))
1594 (while (looking-at re)
1595 (end-of-line 1)
1596 (or (eobp) (forward-char 1)))
1597 (add-text-properties beg (if (bolp) (1- (point)) (point))
1598 '(org-protected t)))))
1600 (defun org-export-select-backend-specific-text ()
1601 (let ((formatters
1602 '((docbook "DOCBOOK" "BEGIN_DOCBOOK" "END_DOCBOOK")
1603 (html "HTML" "BEGIN_HTML" "END_HTML")
1604 (beamer "BEAMER" "BEGIN_BEAMER" "END_BEAMER")
1605 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1606 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1607 (case-fold-search t)
1608 fmt beg beg-content end end-content ind)
1610 (while formatters
1611 (setq fmt (pop formatters))
1612 ;; Handle #+backend: stuff
1613 (goto-char (point-min))
1614 (while (re-search-forward (concat "^\\([ \t]*\\)#\\+" (cadr fmt)
1615 ":[ \t]*\\(.*\\)") nil t)
1616 (if (not (eq (car fmt) org-export-current-backend))
1617 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))
1618 (replace-match "\\1\\2" t)
1619 (add-text-properties
1620 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1621 `(org-protected t original-indentation ,ind))))
1622 ;; Delete #+attr_Backend: stuff of another backend. Those
1623 ;; matching the current backend will be taken care of by
1624 ;; `org-export-attach-captions-and-attributes'
1625 (goto-char (point-min))
1626 (while (re-search-forward (concat "^\\([ \t]*\\)#\\+attr_" (cadr fmt)
1627 ":[ \t]*\\(.*\\)") nil t)
1628 (setq ind (org-get-indentation))
1629 (when (not (eq (car fmt) org-export-current-backend))
1630 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1631 ;; Handle #+begin_backend and #+end_backend stuff
1632 (goto-char (point-min))
1633 (while (re-search-forward (concat "^[ \t]*#\\+" (caddr fmt) "\\>.*\n?")
1634 nil t)
1635 (setq beg (match-beginning 0) beg-content (match-end 0))
1636 (setq ind (save-excursion (goto-char beg) (org-get-indentation)))
1637 (when (re-search-forward (concat "^[ \t]*#\\+" (cadddr fmt) "\\>.*\n?")
1638 nil t)
1639 (setq end (match-end 0) end-content (match-beginning 0))
1640 (if (eq (car fmt) org-export-current-backend)
1641 ;; yes, keep this
1642 (progn
1643 (add-text-properties
1644 beg-content end-content
1645 `(org-protected t original-indentation ,ind))
1646 (delete-region (match-beginning 0) (match-end 0))
1647 (save-excursion
1648 (goto-char beg)
1649 (delete-region (point) (1+ (point-at-eol)))))
1650 ;; No, this is for a different backend, kill it
1651 (delete-region beg end)))))))
1653 (defun org-export-mark-blockquote-verse-center ()
1654 "Mark block quote and verse environments with special cookies.
1655 These special cookies will later be interpreted by the backend."
1656 ;; Blockquotes
1657 (let (type t1 ind beg end beg1 end1 content)
1658 (goto-char (point-min))
1659 (while (re-search-forward
1660 "^\\([ \t]*\\)#\\+\\(begin_\\(\\(block\\)?quote\\|verse\\|center\\)\\>.*\\)"
1661 nil t)
1662 (setq ind (length (match-string 1))
1663 type (downcase (match-string 3))
1664 t1 (if (equal type "quote") "blockquote" type))
1665 (setq beg (match-beginning 0)
1666 beg1 (1+ (match-end 0)))
1667 (when (re-search-forward (concat "^[ \t]*#\\+end_" type "\\>.*") nil t)
1668 (setq end1 (1- (match-beginning 0))
1669 end (+ (point-at-eol) (if (looking-at "\n$") 1 0)))
1670 (setq content (org-remove-indentation (buffer-substring beg1 end1)))
1671 (setq content (concat "ORG-" (upcase t1) "-START\n"
1672 content "\n"
1673 "ORG-" (upcase t1) "-END\n"))
1674 (delete-region beg end)
1675 (insert (org-add-props content nil 'original-indentation ind))))))
1677 (defun org-export-mark-list-end ()
1678 "Mark all list endings with a special string."
1679 (unless (eq org-export-current-backend 'ascii)
1680 (mapc
1681 (lambda (e)
1682 ;; For each type allowing list export, find every list, remove
1683 ;; ending regexp if needed, and insert org-list-end.
1684 (goto-char (point-min))
1685 (while (re-search-forward (org-item-beginning-re) nil t)
1686 (when (eq (nth 2 (org-list-context)) e)
1687 (let* ((struct (org-list-struct))
1688 (bottom (org-list-get-bottom-point struct))
1689 (top (point-at-bol))
1690 (top-ind (org-list-get-ind top struct)))
1691 (goto-char bottom)
1692 (when (and (not (eq org-list-ending-method 'indent))
1693 (looking-at org-list-end-re))
1694 (replace-match ""))
1695 (unless (bolp) (insert "\n"))
1696 ;; As org-list-end is inserted at column 0, it would end
1697 ;; by indentation any list. It can be problematic when
1698 ;; there are lists within lists: the inner list end would
1699 ;; also become the outer list end. To avoid this, text
1700 ;; property `original-indentation' is added, as
1701 ;; `org-list-struct' pays attention to it when reading a
1702 ;; list.
1703 (insert (org-add-props
1704 "ORG-LIST-END-MARKER\n"
1705 (list 'original-indentation top-ind)))))))
1706 (cons nil org-list-export-context))))
1708 (defun org-export-mark-list-properties ()
1709 "Mark list with special properties.
1710 These special properties will later be interpreted by the backend."
1711 (let ((mark-list
1712 (function
1713 ;; Mark a list with 3 properties: `list-item' which is
1714 ;; position at beginning of line, `list-struct' which is
1715 ;; list structure, and `list-prevs' which is the alist of
1716 ;; item and its predecessor. Leave point at list ending.
1717 (lambda (ctxt)
1718 (let* ((struct (org-list-struct))
1719 (top (org-list-get-top-point struct))
1720 (bottom (org-list-get-bottom-point struct))
1721 (prevs (org-list-prevs-alist struct))
1722 poi)
1723 ;; Get every item and ending position, without dups and
1724 ;; without bottom point of list.
1725 (mapc (lambda (e)
1726 (let ((pos (car e))
1727 (end (nth 6 e)))
1728 (unless (memq pos poi)
1729 (push pos poi))
1730 (unless (or (= end bottom) (memq end poi))
1731 (push end poi))))
1732 struct)
1733 (setq poi (sort poi '<))
1734 ;; For every point of interest, mark the whole line with
1735 ;; its position in list.
1736 (mapc
1737 (lambda (e)
1738 (goto-char e)
1739 (add-text-properties (point-at-bol) (point-at-eol)
1740 (list 'list-item (point-at-bol)
1741 'list-struct struct
1742 'list-prevs prevs)))
1743 poi)
1744 ;; Take care of bottom point. As babel may have inserted
1745 ;; a new list in buffer, list ending isn't always
1746 ;; marked. Now mark every list ending and add properties
1747 ;; useful to line processing exporters.
1748 (goto-char bottom)
1749 (when (or (looking-at "^ORG-LIST-END-MARKER\n")
1750 (and (not (eq org-list-ending-method 'indent))
1751 (looking-at org-list-end-re)))
1752 (replace-match ""))
1753 (unless (bolp) (insert "\n"))
1754 (insert
1755 (org-add-props "ORG-LIST-END-MARKER\n" (list 'list-item bottom
1756 'list-struct struct
1757 'list-prevs prevs)))
1758 ;; Following property is used by LaTeX exporter.
1759 (add-text-properties top (point) (list 'list-context ctxt)))))))
1760 ;; Mark lists except for backends not interpreting them.
1761 (unless (eq org-export-current-backend 'ascii)
1762 (let ((org-list-end-re "^ORG-LIST-END-MARKER\n"))
1763 (mapc
1764 (lambda (e)
1765 (goto-char (point-min))
1766 (while (re-search-forward (org-item-beginning-re) nil t)
1767 (when (eq (nth 2 (org-list-context)) e) (funcall mark-list e))))
1768 (cons nil org-list-export-context))))))
1770 (defun org-export-attach-captions-and-attributes (target-alist)
1771 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
1772 If the next thing following is a table, add the text properties to the first
1773 table line. If it is a link, add it to the line containing the link."
1774 (goto-char (point-min))
1775 (remove-text-properties (point-min) (point-max)
1776 '(org-caption nil org-attributes nil))
1777 (let ((case-fold-search t)
1778 (re (concat "^[ \t]*#\\+caption:[ \t]+\\(.*\\)"
1779 "\\|"
1780 "^[ \t]*#\\+attr_" (symbol-name org-export-current-backend) ":[ \t]+\\(.*\\)"
1781 "\\|"
1782 "^[ \t]*#\\+label:[ \t]+\\(.*\\)"
1783 "\\|"
1784 "^[ \t]*\\(|[^-]\\)"
1785 "\\|"
1786 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
1787 cap shortn attr label end)
1788 (while (re-search-forward re nil t)
1789 (cond
1790 ;; there is a caption
1791 ((match-end 1)
1792 (progn
1793 (setq cap (concat cap (if cap " " "") (org-trim (match-string 1))))
1794 (when (string-match "\\[\\(.*\\)\\]{\\(.*\\)}" cap)
1795 (setq shortn (match-string 1 cap)
1796 cap (match-string 2 cap)))
1797 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1798 ;; there is an attribute
1799 ((match-end 2)
1800 (progn
1801 (setq attr (concat attr (if attr " " "") (org-trim (match-string 2))))
1802 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1803 ;; there is a label
1804 ((match-end 3)
1805 (progn
1806 (setq label (org-trim (match-string 3)))
1807 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1809 (setq end (if (match-end 4)
1810 (let ((ee (org-table-end)))
1811 (prog1 (1- (marker-position ee)) (move-marker ee nil)))
1812 (point-at-eol)))
1813 (add-text-properties (point-at-bol) end
1814 (list 'org-caption cap
1815 'org-caption-shortn shortn
1816 'org-attributes attr
1817 'org-label label))
1818 (if label (push (cons label label) target-alist))
1819 (goto-char end)
1820 (setq cap nil attr nil label nil)))))
1821 target-alist)
1823 (defun org-export-remove-comment-blocks-and-subtrees ()
1824 "Remove the comment environment, and also commented subtrees."
1825 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string "\\>"))
1826 case-fold-search)
1827 ;; Remove comment environment
1828 (goto-char (point-min))
1829 (setq case-fold-search t)
1830 (while (re-search-forward
1831 "^#\\+begin_comment[ \t]*\n[^\000]*?^#\\+end_comment\\>.*" nil t)
1832 (replace-match "" t t))
1833 ;; Remove subtrees that are commented
1834 (goto-char (point-min))
1835 (setq case-fold-search nil)
1836 (while (re-search-forward re-commented nil t)
1837 (goto-char (match-beginning 0))
1838 (delete-region (point) (org-end-of-subtree t)))))
1840 (defun org-export-handle-comments (commentsp)
1841 "Remove comments, or convert to backend-specific format.
1842 COMMENTSP can be a format string for publishing comments.
1843 When it is nil, all comments will be removed."
1844 (let ((re "^\\(#\\|[ \t]*#\\+ \\)\\(.*\n?\\)")
1845 pos)
1846 (goto-char (point-min))
1847 (while (or (looking-at re)
1848 (re-search-forward re nil t))
1849 (setq pos (match-beginning 0))
1850 (if (get-text-property pos 'org-protected)
1851 (goto-char (1+ pos))
1852 (if (and commentsp
1853 (not (equal (char-before (match-end 1)) ?+)))
1854 (progn (add-text-properties
1855 (match-beginning 0) (match-end 0) '(org-protected t))
1856 (replace-match (format commentsp (match-string 2)) t t))
1857 (goto-char (1+ pos))
1858 (replace-match "")
1859 (goto-char (max (point-min) (1- pos))))))))
1861 (defun org-export-handle-table-metalines ()
1862 "Remove table specific metalines #+TBLNAME: and #+TBLFM:."
1863 (let ((re "^[ \t]*#\\+TBL\\(NAME\\|FM\\):\\(.*\n?\\)")
1864 pos)
1865 (goto-char (point-min))
1866 (while (or (looking-at re)
1867 (re-search-forward re nil t))
1868 (setq pos (match-beginning 0))
1869 (if (get-text-property (match-beginning 1) 'org-protected)
1870 (goto-char (1+ pos))
1871 (goto-char (1+ pos))
1872 (replace-match "")
1873 (goto-char (max (point-min) (1- pos)))))))
1875 (defun org-export-mark-radio-links ()
1876 "Find all matches for radio targets and turn them into internal links."
1877 (let ((re-radio (and org-target-link-regexp
1878 (concat "\\([^<]\\)\\(" org-target-link-regexp "\\)"))))
1879 (goto-char (point-min))
1880 (when re-radio
1881 (while (re-search-forward re-radio nil t)
1882 (unless
1883 (save-match-data
1884 (or (org-in-regexp org-bracket-link-regexp)
1885 (org-in-regexp org-plain-link-re)
1886 (org-in-regexp "<<[^<>]+>>")))
1887 (org-if-unprotected
1888 (replace-match "\\1[[\\2]]")))))))
1890 (defun org-store-forced-table-alignment ()
1891 "Find table lines which force alignment, store the results in properties."
1892 (let (line cnt aligns)
1893 (goto-char (point-min))
1894 (while (re-search-forward "|[ \t]*<[lrc][0-9]*>[ \t]*|" nil t)
1895 ;; OK, this looks like a table line with an alignment cookie
1896 (org-if-unprotected
1897 (setq line (buffer-substring (point-at-bol) (point-at-eol)))
1898 (when (and (org-at-table-p)
1899 (org-table-cookie-line-p line))
1900 (setq cnt 0 aligns nil)
1901 (mapc
1902 (lambda (x)
1903 (setq cnt (1+ cnt))
1904 (if (string-match "\\`<\\([lrc]\\)" x)
1905 (push (cons cnt (downcase (match-string 1 x))) aligns)))
1906 (org-split-string line "[ \t]*|[ \t]*"))
1907 (add-text-properties (org-table-begin) (org-table-end)
1908 (list 'org-forced-aligns aligns))))
1909 (goto-char (point-at-eol)))))
1911 (defun org-export-remove-special-table-lines ()
1912 "Remove tables lines that are used for internal purposes.
1913 Also, store forced alignment information found in such lines."
1914 (goto-char (point-min))
1915 (while (re-search-forward "^[ \t]*|" nil t)
1916 (org-if-unprotected-at (1- (point))
1917 (beginning-of-line 1)
1918 (if (or (looking-at "[ \t]*| *[!_^] *|")
1919 (not
1920 (memq
1922 (mapcar
1923 (lambda (f)
1924 (or (and org-export-table-remove-empty-lines (= (length f) 0))
1925 (string-match
1926 "\\`<\\([0-9]\\|[lrc]\\|[lrc][0-9]+\\)>\\'" f)))
1927 (org-split-string ;; FIXME, can't we do without splitting???
1928 (buffer-substring (point-at-bol) (point-at-eol))
1929 "[ \t]*|[ \t]*")))))
1930 (delete-region (max (point-min) (1- (point-at-bol)))
1931 (point-at-eol))
1932 (end-of-line 1)))))
1934 (defun org-export-protect-sub-super (s)
1935 (save-match-data
1936 (while (string-match "\\([^\\\\]\\)\\([_^]\\)" s)
1937 (setq s (replace-match "\\1\\\\\\2" nil nil s)))
1940 (defun org-export-normalize-links ()
1941 "Convert all links to bracket links, and expand link abbreviations."
1942 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re))
1943 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re))
1944 nodesc)
1945 (goto-char (point-min))
1946 (while (re-search-forward re-plain-link nil t)
1947 (unless (org-string-match-p
1948 "\\[\\[\\S-+:\\S-*?\\<"
1949 (buffer-substring (point-at-bol) (match-beginning 0)))
1950 (goto-char (1- (match-end 0)))
1951 (org-if-unprotected-at (1+ (match-beginning 0))
1952 (let* ((s (concat (match-string 1)
1953 "[[" (match-string 2) ":" (match-string 3)
1954 "][" (match-string 2) ":" (org-export-protect-sub-super
1955 (match-string 3))
1956 "]]")))
1957 ;; added 'org-link face to links
1958 (put-text-property 0 (length s) 'face 'org-link s)
1959 (replace-match s t t)))))
1960 (goto-char (point-min))
1961 (while (re-search-forward re-angle-link nil t)
1962 (goto-char (1- (match-end 0)))
1963 (org-if-unprotected
1964 (let* ((s (concat (match-string 1)
1965 "[[" (match-string 2) ":" (match-string 3)
1966 "][" (match-string 2) ":" (org-export-protect-sub-super
1967 (match-string 3))
1968 "]]")))
1969 (put-text-property 0 (length s) 'face 'org-link s)
1970 (replace-match s t t))))
1971 (goto-char (point-min))
1972 (while (re-search-forward org-bracket-link-regexp nil t)
1973 (goto-char (1- (match-end 0)))
1974 (setq nodesc (not (match-end 3)))
1975 (org-if-unprotected
1976 (let* ((xx (save-match-data
1977 (org-translate-link
1978 (org-link-expand-abbrev (match-string 1)))))
1979 (s (concat
1980 "[[" (org-add-props (copy-sequence xx)
1981 nil 'org-protected t 'org-no-description nodesc)
1983 (if (match-end 3)
1984 (match-string 2)
1985 (concat "[" (copy-sequence xx)
1986 "]"))
1987 "]")))
1988 (put-text-property 0 (length s) 'face 'org-link s)
1989 (replace-match s t t))))))
1991 (defun org-export-concatenate-multiline-links ()
1992 "Find multi-line links and put it all into a single line.
1993 This is to make sure that the line-processing export backends
1994 can work correctly."
1995 (goto-char (point-min))
1996 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t)
1997 (org-if-unprotected-at (match-beginning 1)
1998 (replace-match "\\1 \\3")
1999 (goto-char (match-beginning 0)))))
2001 (defun org-export-concatenate-multiline-emphasis ()
2002 "Find multi-line emphasis and put it all into a single line.
2003 This is to make sure that the line-processing export backends
2004 can work correctly."
2005 (goto-char (point-min))
2006 (while (re-search-forward org-emph-re nil t)
2007 (if (and (not (= (char-after (match-beginning 3))
2008 (char-after (match-beginning 4))))
2009 (save-excursion (goto-char (match-beginning 0))
2010 (save-match-data
2011 (and (not (org-at-table-p))
2012 (not (org-at-heading-p))))))
2013 (org-if-unprotected
2014 (subst-char-in-region (match-beginning 0) (match-end 0)
2015 ?\n ?\ t)
2016 (goto-char (1- (match-end 0))))
2017 (goto-char (1+ (match-beginning 0))))))
2019 (defun org-export-grab-title-from-buffer ()
2020 "Get a title for the current document, from looking at the buffer."
2021 (let ((inhibit-read-only t))
2022 (save-excursion
2023 (goto-char (point-min))
2024 (let ((end (if (looking-at org-outline-regexp)
2025 (point)
2026 (save-excursion (outline-next-heading) (point)))))
2027 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t)
2028 ;; Mark the line so that it will not be exported as normal text.
2029 (org-unmodified
2030 (add-text-properties (match-beginning 0) (match-end 0)
2031 (list :org-license-to-kill t)))
2032 ;; Return the title string
2033 (org-trim (match-string 0)))))))
2035 (defun org-export-get-title-from-subtree ()
2036 "Return subtree title and exclude it from export."
2037 (let ((rbeg (region-beginning)) (rend (region-end))
2038 (inhibit-read-only t) title)
2039 (save-excursion
2040 (goto-char rbeg)
2041 (when (and (org-at-heading-p)
2042 (>= (org-end-of-subtree t t) rend))
2043 ;; This is a subtree, we take the title from the first heading
2044 (goto-char rbeg)
2045 (looking-at org-todo-line-regexp)
2046 (setq title (match-string 3))
2047 (org-unmodified
2048 (add-text-properties (point) (1+ (point-at-eol))
2049 (list :org-license-to-kill t)))
2050 (setq title (or (org-entry-get nil "EXPORT_TITLE") title))))
2051 title))
2053 (defun org-solidify-link-text (s &optional alist)
2054 "Take link text and make a safe target out of it."
2055 (save-match-data
2056 (let* ((rtn
2057 (mapconcat
2058 'identity
2059 (org-split-string s "[^a-zA-Z0-9_\\.-]+") "-"))
2060 (a (assoc rtn alist)))
2061 (or (cdr a) rtn))))
2063 (defun org-get-min-level (lines &optional offset)
2064 "Get the minimum level in LINES."
2065 (let ((re "^\\(\\*+\\) ") l)
2066 (catch 'exit
2067 (while (setq l (pop lines))
2068 (if (string-match re l)
2069 (throw 'exit (org-tr-level (- (length (match-string 1 l))
2070 (or offset 0))))))
2071 1)))
2073 ;; Variable holding the vector with section numbers
2074 (defvar org-section-numbers (make-vector org-level-max 0))
2076 (defun org-init-section-numbers ()
2077 "Initialize the vector for the section numbers."
2078 (let* ((level -1)
2079 (numbers (nreverse (org-split-string "" "\\.")))
2080 (depth (1- (length org-section-numbers)))
2081 (i depth) number-string)
2082 (while (>= i 0)
2083 (if (> i level)
2084 (aset org-section-numbers i 0)
2085 (setq number-string (or (car numbers) "0"))
2086 (if (string-match "\\`[A-Z]\\'" number-string)
2087 (aset org-section-numbers i
2088 (- (string-to-char number-string) ?A -1))
2089 (aset org-section-numbers i (string-to-number number-string)))
2090 (pop numbers))
2091 (setq i (1- i)))))
2093 (defun org-section-number (&optional level)
2094 "Return a string with the current section number.
2095 When LEVEL is non-nil, increase section numbers on that level."
2096 (let* ((depth (1- (length org-section-numbers)))
2097 (string "")
2098 (fmts (car org-export-section-number-format))
2099 (term (cdr org-export-section-number-format))
2100 (sep "")
2101 ctype fmt idx n)
2102 (when level
2103 (when (> level -1)
2104 (aset org-section-numbers
2105 level (1+ (aref org-section-numbers level))))
2106 (setq idx (1+ level))
2107 (while (<= idx depth)
2108 (if (not (= idx 1))
2109 (aset org-section-numbers idx 0))
2110 (setq idx (1+ idx))))
2111 (setq idx 0)
2112 (while (<= idx depth)
2113 (when (> (aref org-section-numbers idx) 0)
2114 (setq fmt (or (pop fmts) fmt)
2115 ctype (car fmt)
2116 n (aref org-section-numbers idx)
2117 string (if (> n 0)
2118 (concat string sep (org-number-to-counter n ctype))
2119 (concat string ".0"))
2120 sep (nth 1 fmt)))
2121 (setq idx (1+ idx)))
2122 (save-match-data
2123 (if (string-match "\\`\\([@0]\\.\\)+" string)
2124 (setq string (replace-match "" t nil string)))
2125 (if (string-match "\\(\\.0\\)+\\'" string)
2126 (setq string (replace-match "" t nil string))))
2127 (concat string term)))
2129 (defun org-number-to-counter (n type)
2130 "Concert number N to a string counter, according to TYPE.
2131 TYPE must be a string, any of:
2132 1 number
2133 A A,B,....
2134 a a,b,....
2135 I upper case roman numeral
2136 i lower case roman numeral"
2137 (cond
2138 ((equal type "1") (number-to-string n))
2139 ((equal type "A") (char-to-string (+ ?A n -1)))
2140 ((equal type "a") (char-to-string (+ ?a n -1)))
2141 ((equal type "I") (org-number-to-roman n))
2142 ((equal type "i") (downcase (org-number-to-roman n)))
2143 (t (error "Invalid counter type `%s'" type))))
2145 (defun org-number-to-roman (n)
2146 "Convert integer N into a roman numeral."
2147 (let ((roman '((1000 . "M") (900 . "CM") (500 . "D") (400 . "CD")
2148 ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL")
2149 ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV")
2150 ( 1 . "I")))
2151 (res ""))
2152 (if (<= n 0)
2153 (number-to-string n)
2154 (while roman
2155 (if (>= n (caar roman))
2156 (setq n (- n (caar roman))
2157 res (concat res (cdar roman)))
2158 (pop roman)))
2159 res)))
2161 ;;; Macros
2163 (defun org-export-preprocess-apply-macros ()
2164 "Replace macro references."
2165 (goto-char (point-min))
2166 (let (sy val key args args2 s n)
2167 (while (re-search-forward
2168 "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)\\(([ \t\n]*\\([^\000]*?\\))\\)?}}}"
2169 nil t)
2170 (unless (save-match-data
2171 (save-excursion
2172 (goto-char (point-at-bol))
2173 (looking-at "[ \t]*#\\+macro")))
2174 (setq key (downcase (match-string 1))
2175 args (match-string 3))
2176 (when (setq val (or (plist-get org-export-opt-plist
2177 (intern (concat ":macro-" key)))
2178 (plist-get org-export-opt-plist
2179 (intern (concat ":" key)))))
2180 (save-match-data
2181 (when args
2182 (setq args (org-split-string args ",") args2 nil)
2183 (while args
2184 (while (string-match "\\\\\\'" (car args))
2185 ;; repair bad splits
2186 (setcar (cdr args) (concat (substring (car args) 0 -1)
2187 "," (nth 1 args)))
2188 (pop args))
2189 (push (pop args) args2))
2190 (setq args (mapcar 'org-trim (nreverse args2)))
2191 (setq s 0)
2192 (while (string-match "\\$\\([0-9]+\\)" val s)
2193 (setq s (1+ (match-beginning 0))
2194 n (string-to-number (match-string 1 val)))
2195 (and (>= (length args) n)
2196 (setq val (replace-match (nth (1- n) args) t t val)))))
2197 (when (string-match "\\`(eval\\>" val)
2198 (setq val (eval (read val))))
2199 (if (and val (not (stringp val)))
2200 (setq val (format "%s" val))))
2201 (and (stringp val)
2202 (prog1 (replace-match val t t)
2203 (goto-char (match-beginning 0)))))))))
2205 (defun org-export-apply-macros-in-string (s)
2206 "Apply the macros in string S."
2207 (when s
2208 (with-temp-buffer
2209 (insert s)
2210 (org-export-preprocess-apply-macros)
2211 (buffer-string))))
2213 ;;; Include files
2215 (defun org-export-handle-include-files ()
2216 "Include the contents of include files, with proper formatting."
2217 (let ((case-fold-search t)
2218 params file markup lang start end prefix prefix1 switches all minlevel lines)
2219 (goto-char (point-min))
2220 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t)
2221 (setq params (read (concat "(" (match-string 1) ")"))
2222 prefix (org-get-and-remove-property 'params :prefix)
2223 prefix1 (org-get-and-remove-property 'params :prefix1)
2224 minlevel (org-get-and-remove-property 'params :minlevel)
2225 lines (org-get-and-remove-property 'params :lines)
2226 file (org-symname-or-string (pop params))
2227 markup (org-symname-or-string (pop params))
2228 lang (and (member markup '("src" "SRC"))
2229 (org-symname-or-string (pop params)))
2230 switches (mapconcat '(lambda (x) (format "%s" x)) params " ")
2231 start nil end nil)
2232 (delete-region (match-beginning 0) (match-end 0))
2233 (if (or (not file)
2234 (not (file-exists-p file))
2235 (not (file-readable-p file)))
2236 (insert (format "CANNOT INCLUDE FILE %s" file))
2237 (setq all (cons file all))
2238 (when markup
2239 (if (equal (downcase markup) "src")
2240 (setq start (format "#+begin_src %s %s\n"
2241 (or lang "fundamental")
2242 (or switches ""))
2243 end "#+end_src")
2244 (setq start (format "#+begin_%s %s\n" markup switches)
2245 end (format "#+end_%s" markup))))
2246 (insert (or start ""))
2247 (insert (org-get-file-contents (expand-file-name file)
2248 prefix prefix1 markup minlevel lines))
2249 (or (bolp) (newline))
2250 (insert (or end ""))))
2251 all))
2253 (defun org-export-handle-include-files-recurse ()
2254 "Recursively include files aborting on circular inclusion."
2255 (let ((now (list org-current-export-file)) all)
2256 (while now
2257 (setq all (append now all))
2258 (setq now (org-export-handle-include-files))
2259 (let ((intersection
2260 (delq nil
2261 (mapcar (lambda (el) (when (member el all) el)) now))))
2262 (when intersection
2263 (error "Recursive #+INCLUDE: %S" intersection))))))
2265 (defun org-get-file-contents (file &optional prefix prefix1 markup minlevel lines)
2266 "Get the contents of FILE and return them as a string.
2267 If PREFIX is a string, prepend it to each line. If PREFIX1
2268 is a string, prepend it to the first line instead of PREFIX.
2269 If MARKUP, don't protect org-like lines, the exporter will
2270 take care of the block they are in. If LINES is a string
2271 specifying a range of lines, include only those lines ."
2272 (if (stringp markup) (setq markup (downcase markup)))
2273 (with-temp-buffer
2274 (insert-file-contents file)
2275 (when lines
2276 (let* ((lines (split-string lines "-"))
2277 (lbeg (string-to-number (car lines)))
2278 (lend (string-to-number (cadr lines)))
2279 (beg (if (zerop lbeg) (point-min)
2280 (goto-char (point-min))
2281 (forward-line (1- lbeg))
2282 (point)))
2283 (end (if (zerop lend) (point-max)
2284 (goto-char (point-min))
2285 (forward-line (1- lend))
2286 (point))))
2287 (narrow-to-region beg end)))
2288 (when (or prefix prefix1)
2289 (goto-char (point-min))
2290 (while (not (eobp))
2291 (insert (or prefix1 prefix))
2292 (setq prefix1 "")
2293 (beginning-of-line 2)))
2294 (buffer-string)
2295 (when (member markup '("src" "example"))
2296 (goto-char (point-min))
2297 (while (re-search-forward "^\\([*#]\\|[ \t]*#\\+\\)" nil t)
2298 (goto-char (match-beginning 0))
2299 (insert ",")
2300 (end-of-line 1)))
2301 (when minlevel
2302 (dotimes (lvl minlevel)
2303 (org-map-region 'org-demote (point-min) (point-max))))
2304 (buffer-string)))
2306 (defun org-get-and-remove-property (listvar prop)
2307 "Check if the value of LISTVAR contains PROP as a property.
2308 If yes, return the value of that property (i.e. the element following
2309 in the list) and remove property and value from the list in LISTVAR."
2310 (let ((list (symbol-value listvar)) m v)
2311 (when (setq m (member prop list))
2312 (setq v (nth 1 m))
2313 (if (equal (car list) prop)
2314 (set listvar (cddr list))
2315 (setcdr (nthcdr (- (length list) (length m) 1) list)
2316 (cddr m))
2317 (set listvar list)))
2320 (defun org-symname-or-string (s)
2321 (if (symbolp s)
2322 (if s (symbol-name s) s)
2325 ;;; Fontification and line numbers for code examples
2327 (defvar org-export-last-code-line-counter-value 0)
2329 (defun org-export-replace-src-segments-and-examples ()
2330 "Replace source code segments with special code for export."
2331 (setq org-export-last-code-line-counter-value 0)
2332 (let ((case-fold-search t)
2333 lang code trans opts indent caption)
2334 (goto-char (point-min))
2335 (while (re-search-forward
2336 "\\(^\\([ \t]*\\)#\\+BEGIN_SRC:?\\([ \t]+\\([^ \t\n]+\\)\\)?\\(.*\\)\n\\([^\000]+?\n\\)[ \t]*#\\+END_SRC.*\n?\\)\\|\\(^\\([ \t]*\\)#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)[ \t]*#\\+END_EXAMPLE.*\n?\\)"
2337 nil t)
2338 (if (match-end 1)
2339 (if (not (match-string 4))
2340 (error "Source block missing language specification: %s"
2341 (let* ((body (match-string 6))
2342 (nothing (message "body:%s" body))
2343 (preview (or (and (string-match
2344 "^[ \t]*\\([^\n\r]*\\)" body)
2345 (match-string 1 body)) body)))
2346 (if (> (length preview) 35)
2347 (concat (substring preview 0 32) "...")
2348 preview)))
2349 ;; src segments
2350 (setq lang (match-string 4)
2351 opts (match-string 5)
2352 code (match-string 6)
2353 indent (length (match-string 2))
2354 caption (get-text-property 0 'org-caption (match-string 0))))
2355 (setq lang nil
2356 opts (match-string 9)
2357 code (match-string 10)
2358 indent (length (match-string 8))
2359 caption (get-text-property 0 'org-caption (match-string 0))))
2361 (setq trans (org-export-format-source-code-or-example
2362 lang code opts indent caption))
2363 (replace-match trans t t))))
2365 (defvar org-export-latex-verbatim-wrap) ;; defined in org-latex.el
2366 (defvar org-export-latex-listings) ;; defined in org-latex.el
2367 (defvar org-export-latex-listings-langs) ;; defined in org-latex.el
2368 (defvar org-export-latex-listings-w-names) ;; defined in org-latex.el
2369 (defvar org-export-latex-minted-langs) ;; defined in org-latex.el
2370 (defvar org-export-latex-custom-lang-environments) ;; defined in org-latex.el
2371 (defvar org-export-latex-listings-options) ;; defined in org-latex.el
2372 (defvar org-export-latex-minted-options) ;; defined in org-latex.el
2374 (defun org-export-format-source-code-or-example
2375 (lang code &optional opts indent caption)
2376 "Format CODE from language LANG and return it formatted for export.
2377 If LANG is nil, do not add any fontification.
2378 OPTS contains formatting options, like `-n' for triggering numbering lines,
2379 and `+n' for continuing previous numbering.
2380 Code formatting according to language currently only works for HTML.
2381 Numbering lines works for all three major backends (html, latex, and ascii).
2382 INDENT was the original indentation of the block."
2383 (save-match-data
2384 (let (num cont rtn rpllbl keepp textareap preserve-indentp cols rows fmt)
2385 (setq opts (or opts "")
2386 num (string-match "[-+]n\\>" opts)
2387 cont (string-match "\\+n\\>" opts)
2388 rpllbl (string-match "-r\\>" opts)
2389 keepp (string-match "-k\\>" opts)
2390 textareap (string-match "-t\\>" opts)
2391 preserve-indentp (or org-src-preserve-indentation
2392 (string-match "-i\\>" opts))
2393 cols (if (string-match "-w[ \t]+\\([0-9]+\\)" opts)
2394 (string-to-number (match-string 1 opts))
2396 rows (if (string-match "-h[ \t]+\\([0-9]+\\)" opts)
2397 (string-to-number (match-string 1 opts))
2398 (org-count-lines code))
2399 fmt (if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts)
2400 (match-string 1 opts)))
2401 (when (and textareap (eq org-export-current-backend 'html))
2402 ;; we cannot use numbering or highlighting.
2403 (setq num nil cont nil lang nil))
2404 (if keepp (setq rpllbl 'keep))
2405 (setq rtn (if preserve-indentp code (org-remove-indentation code)))
2406 (when (string-match "^," rtn)
2407 (setq rtn (with-temp-buffer
2408 (insert rtn)
2409 ;; Free up the protected lines
2410 (goto-char (point-min))
2411 (while (re-search-forward "^," nil t)
2412 (if (or (equal lang "org")
2413 (save-match-data
2414 (looking-at "\\([*#]\\|[ \t]*#\\+\\)")))
2415 (replace-match ""))
2416 (end-of-line 1))
2417 (buffer-string))))
2418 ;; Now backend-specific coding
2419 (setq rtn
2420 (cond
2421 ((eq org-export-current-backend 'docbook)
2422 (setq rtn (org-export-number-lines rtn 0 0 num cont rpllbl fmt))
2423 (concat "\n#+BEGIN_DOCBOOK\n"
2424 (org-add-props (concat "<programlisting><![CDATA["
2426 "]]></programlisting>\n")
2427 '(org-protected t org-example t))
2428 "#+END_DOCBOOK\n"))
2429 ((eq org-export-current-backend 'html)
2430 ;; We are exporting to HTML
2431 (when lang
2432 (if (featurep 'xemacs)
2433 (require 'htmlize)
2434 (require 'htmlize nil t))
2435 (when (not (fboundp 'htmlize-region-for-paste))
2436 ;; we do not have htmlize.el, or an old version of it
2437 (setq lang nil)
2438 (message
2439 "htmlize.el 1.34 or later is needed for source code formatting")))
2441 (if lang
2442 (let* ((lang-m (when lang
2443 (or (cdr (assoc lang org-src-lang-modes))
2444 lang)))
2445 (mode (and lang-m (intern
2446 (concat
2447 (if (symbolp lang-m)
2448 (symbol-name lang-m)
2449 lang-m)
2450 "-mode"))))
2451 (org-inhibit-startup t)
2452 (org-startup-folded nil))
2453 (setq rtn
2454 (with-temp-buffer
2455 (insert rtn)
2456 (if (functionp mode)
2457 (funcall mode)
2458 (fundamental-mode))
2459 (font-lock-fontify-buffer)
2460 (org-src-mode)
2461 (set-buffer-modified-p nil)
2462 (org-export-htmlize-region-for-paste
2463 (point-min) (point-max))))
2464 (if (string-match "<pre\\([^>]*\\)>\n*" rtn)
2465 (setq rtn
2466 (concat
2467 (if caption
2468 (concat
2469 "<div class=\"org-src-container\">"
2470 (format
2471 "<label class=\"org-src-name\">%s</label>"
2472 caption))
2474 (replace-match
2475 (format "<pre class=\"src src-%s\">\n" lang)
2476 t t rtn)
2477 (if caption "</div>" "")))))
2478 (if textareap
2479 (setq rtn (concat
2480 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\">"
2481 cols rows)
2482 rtn "</textarea>\n</p>\n"))
2483 (with-temp-buffer
2484 (insert rtn)
2485 (goto-char (point-min))
2486 (while (re-search-forward "[<>&]" nil t)
2487 (replace-match (cdr (assq (char-before)
2488 '((?&."&amp;")(?<."&lt;")(?>."&gt;"))))
2489 t t))
2490 (setq rtn (buffer-string)))
2491 (setq rtn (concat "<pre class=\"example\">\n" rtn "</pre>\n"))))
2492 (unless textareap
2493 (setq rtn (org-export-number-lines rtn 1 1 num cont rpllbl fmt)))
2494 (if (string-match "\\(\\`<[^>]*>\\)\n" rtn)
2495 (setq rtn (replace-match "\\1" t nil rtn)))
2496 (concat "\n#+BEGIN_HTML\n" (org-add-props rtn '(org-protected t org-example t)) "\n#+END_HTML\n\n"))
2497 ((eq org-export-current-backend 'latex)
2498 (setq rtn (org-export-number-lines rtn 0 0 num cont rpllbl fmt))
2499 (concat
2500 "#+BEGIN_LaTeX\n"
2501 (org-add-props
2502 (cond
2503 ((and lang org-export-latex-listings)
2504 (flet ((make-option-string
2505 (pair)
2506 (concat (first pair)
2507 (if (> (length (second pair)) 0)
2508 (concat "=" (second pair))))))
2509 (let* ((lang-sym (intern lang))
2510 (minted-p (eq org-export-latex-listings 'minted))
2511 (listings-p (not minted-p))
2512 (backend-lang
2513 (or (cadr
2514 (assq
2515 lang-sym
2516 (cond
2517 (minted-p org-export-latex-minted-langs)
2518 (listings-p org-export-latex-listings-langs))))
2519 lang))
2520 (custom-environment
2521 (cadr
2522 (assq
2523 lang-sym
2524 org-export-latex-custom-lang-environments))))
2525 (concat
2526 (when (and listings-p (not custom-environment))
2527 (format
2528 "\\lstset{%s}\n"
2529 (mapconcat
2530 #'make-option-string
2531 (append org-export-latex-listings-options
2532 `(("language" ,backend-lang))) ",")))
2533 (when (and caption org-export-latex-listings-w-names)
2534 (format
2535 "\n%s $\\equiv$ \n"
2536 (replace-regexp-in-string "_" "\\\\_" caption)))
2537 (cond
2538 (custom-environment
2539 (format "\\begin{%s}\n%s\\end{%s}\n"
2540 custom-environment rtn custom-environment))
2541 (listings-p
2542 (format "\\begin{%s}\n%s\\end{%s}\n"
2543 "lstlisting" rtn "lstlisting"))
2544 (minted-p
2545 (format
2546 "\\begin{minted}[%s]{%s}\n%s\\end{minted}\n"
2547 (mapconcat #'make-option-string
2548 org-export-latex-minted-options ",")
2549 backend-lang rtn)))))))
2550 (t (concat (car org-export-latex-verbatim-wrap)
2551 rtn (cdr org-export-latex-verbatim-wrap))))
2552 '(org-protected t org-example t))
2553 "#+END_LaTeX\n"))
2554 ((eq org-export-current-backend 'ascii)
2555 ;; This is not HTML or LaTeX, so just make it an example.
2556 (setq rtn (org-export-number-lines rtn 0 0 num cont rpllbl fmt))
2557 (concat caption "\n"
2558 "#+BEGIN_ASCII\n"
2559 (org-add-props
2560 (concat
2561 (mapconcat
2562 (lambda (l) (concat " " l))
2563 (org-split-string rtn "\n")
2564 "\n")
2565 "\n")
2566 '(org-protected t org-example t))
2567 "#+END_ASCII\n"))))
2568 (org-add-props rtn nil 'original-indentation indent))))
2570 (defun org-export-number-lines (text &optional skip1 skip2 number cont
2571 replace-labels label-format)
2572 (setq skip1 (or skip1 0) skip2 (or skip2 0))
2573 (if (not cont) (setq org-export-last-code-line-counter-value 0))
2574 (with-temp-buffer
2575 (insert text)
2576 (goto-char (point-max))
2577 (skip-chars-backward " \t\n\r")
2578 (delete-region (point) (point-max))
2579 (beginning-of-line (- 1 skip2))
2580 (let* ((last (org-current-line))
2581 (n org-export-last-code-line-counter-value)
2582 (nmax (+ n (- last skip1)))
2583 (fmt (format "%%%dd: " (length (number-to-string nmax))))
2585 (cond
2586 ((eq org-export-current-backend 'html) (format "<span class=\"linenr\">%s</span>"
2587 fmt))
2588 ((eq org-export-current-backend 'ascii) fmt)
2589 ((eq org-export-current-backend 'latex) fmt)
2590 ((eq org-export-current-backend 'docbook) fmt)
2591 (t "")))
2592 (label-format (or label-format org-coderef-label-format))
2593 (label-pre (if (string-match "%s" label-format)
2594 (substring label-format 0 (match-beginning 0))
2595 label-format))
2596 (label-post (if (string-match "%s" label-format)
2597 (substring label-format (match-end 0))
2598 ""))
2599 (lbl-re
2600 (concat
2601 ".*?\\S-.*?\\([ \t]*\\("
2602 (regexp-quote label-pre)
2603 "\\([-a-zA-Z0-9_ ]+\\)"
2604 (regexp-quote label-post)
2605 "\\)\\)"))
2606 ref)
2608 (org-goto-line (1+ skip1))
2609 (while (and (re-search-forward "^" nil t) (not (eobp)) (< n nmax))
2610 (if number
2611 (insert (format fm (incf n)))
2612 (forward-char 1))
2613 (when (looking-at lbl-re)
2614 (setq ref (match-string 3))
2615 (cond ((numberp replace-labels)
2616 ;; remove labels; use numbers for references when lines
2617 ;; are numbered, use labels otherwise
2618 (delete-region (match-beginning 1) (match-end 1))
2619 (push (cons ref (if (> n 0) n ref)) org-export-code-refs))
2620 ((eq replace-labels 'keep)
2621 ;; don't remove labels; use numbers for references when
2622 ;; lines are numbered, use labels otherwise
2623 (goto-char (match-beginning 2))
2624 (delete-region (match-beginning 2) (match-end 2))
2625 (insert "(" ref ")")
2626 (push (cons ref (if (> n 0) n (concat "(" ref ")")))
2627 org-export-code-refs))
2629 ;; don't remove labels and don't use numbers for
2630 ;; references
2631 (goto-char (match-beginning 2))
2632 (delete-region (match-beginning 2) (match-end 2))
2633 (insert "(" ref ")")
2634 (push (cons ref (concat "(" ref ")")) org-export-code-refs)))
2635 (when (eq org-export-current-backend 'html)
2636 (save-excursion
2637 (beginning-of-line 1)
2638 (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
2639 ref))
2640 (end-of-line 1)
2641 (insert "</span>")))))
2642 (setq org-export-last-code-line-counter-value n)
2643 (goto-char (point-max))
2644 (newline)
2645 (buffer-string))))
2647 (defun org-search-todo-below (line lines level)
2648 "Search the subtree below LINE for any TODO entries."
2649 (let ((rest (cdr (memq line lines)))
2650 (re org-todo-line-regexp)
2651 line lv todo)
2652 (catch 'exit
2653 (while (setq line (pop rest))
2654 (if (string-match re line)
2655 (progn
2656 (setq lv (- (match-end 1) (match-beginning 1))
2657 todo (and (match-beginning 2)
2658 (not (member (match-string 2 line)
2659 org-done-keywords))))
2660 ; TODO, not DONE
2661 (if (<= lv level) (throw 'exit nil))
2662 (if todo (throw 'exit t))))))))
2664 ;;;###autoload
2665 (defun org-export-visible (type arg)
2666 "Create a copy of the visible part of the current buffer, and export it.
2667 The copy is created in a temporary buffer and removed after use.
2668 TYPE is the final key (as a string) that also selects the export command in
2669 the \\<org-mode-map>\\[org-export] export dispatcher.
2670 As a special case, if the you type SPC at the prompt, the temporary
2671 org-mode file will not be removed but presented to you so that you can
2672 continue to use it. The prefix arg ARG is passed through to the exporting
2673 command."
2674 (interactive
2675 (list (progn
2676 (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")
2677 (read-char-exclusive))
2678 current-prefix-arg))
2679 (if (not (member type '(?a ?n ?u ?\C-a ?b ?\C-b ?h ?D ?x ?\ ?l ?p ?d ?L ?H ?R)))
2680 (error "Invalid export key"))
2681 (let* ((binding (cdr (assoc type
2683 (?a . org-export-as-ascii)
2684 (?A . org-export-as-ascii-to-buffer)
2685 (?n . org-export-as-latin1)
2686 (?N . org-export-as-latin1-to-buffer)
2687 (?u . org-export-as-utf8)
2688 (?U . org-export-as-utf8-to-buffer)
2689 (?\C-a . org-export-as-ascii)
2690 (?b . org-export-as-html-and-open)
2691 (?\C-b . org-export-as-html-and-open)
2692 (?h . org-export-as-html)
2693 (?H . org-export-as-html-to-buffer)
2694 (?R . org-export-region-as-html)
2695 (?D . org-export-as-docbook)
2697 (?l . org-export-as-latex)
2698 (?p . org-export-as-pdf)
2699 (?d . org-export-as-pdf-and-open)
2700 (?L . org-export-as-latex-to-buffer)
2702 (?x . org-export-as-xoxo)))))
2703 (keepp (equal type ?\ ))
2704 (file buffer-file-name)
2705 (buffer (get-buffer-create "*Org Export Visible*"))
2706 s e)
2707 ;; Need to hack the drawers here.
2708 (save-excursion
2709 (goto-char (point-min))
2710 (while (re-search-forward org-drawer-regexp nil t)
2711 (goto-char (match-beginning 1))
2712 (or (outline-invisible-p) (org-flag-drawer nil))))
2713 (with-current-buffer buffer (erase-buffer))
2714 (save-excursion
2715 (setq s (goto-char (point-min)))
2716 (while (not (= (point) (point-max)))
2717 (goto-char (org-find-invisible))
2718 (append-to-buffer buffer s (point))
2719 (setq s (goto-char (org-find-visible))))
2720 (org-cycle-hide-drawers 'all)
2721 (goto-char (point-min))
2722 (unless keepp
2723 ;; Copy all comment lines to the end, to make sure #+ settings are
2724 ;; still available for the second export step. Kind of a hack, but
2725 ;; does do the trick.
2726 (if (looking-at "#[^\r\n]*")
2727 (append-to-buffer buffer (match-beginning 0) (1+ (match-end 0))))
2728 (when (re-search-forward "^\\*+[ \t]+" nil t)
2729 (while (re-search-backward "[\n\r]#[^\n\r]*" nil t)
2730 (append-to-buffer buffer (1+ (match-beginning 0))
2731 (min (point-max) (1+ (match-end 0)))))))
2732 (set-buffer buffer)
2733 (let ((buffer-file-name file)
2734 (org-inhibit-startup t))
2735 (org-mode)
2736 (show-all)
2737 (unless keepp (funcall binding arg))))
2738 (if (not keepp)
2739 (kill-buffer buffer)
2740 (switch-to-buffer-other-window buffer)
2741 (goto-char (point-min)))))
2743 (defun org-find-visible ()
2744 (let ((s (point)))
2745 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2746 (get-char-property s 'invisible)))
2748 (defun org-find-invisible ()
2749 (let ((s (point)))
2750 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2751 (not (get-char-property s 'invisible))))
2754 (defvar org-export-htmlized-org-css-url) ;; defined in org-html.el
2756 (defun org-export-string (string fmt &optional dir)
2757 "Export STRING to FMT using existing export facilities.
2758 During export STRING is saved to a temporary file whose location
2759 could vary. Optional argument DIR can be used to force the
2760 directory in which the temporary file is created during export
2761 which can be useful for resolving relative paths. Dir defaults
2762 to the value of `temporary-file-directory'."
2763 (let ((temporary-file-directory (or dir temporary-file-directory))
2764 (tmp-file (make-temp-file "org-")))
2765 (unwind-protect
2766 (with-temp-buffer
2767 (insert string)
2768 (write-file tmp-file)
2769 (org-load-modules-maybe)
2770 (unless org-local-vars
2771 (setq org-local-vars (org-get-local-variables)))
2772 (eval ;; convert to fmt -- mimicing `org-run-like-in-org-mode'
2773 (list 'let org-local-vars
2774 (list (intern (format "org-export-as-%s" fmt))
2775 nil nil nil ''string t))))
2776 (delete-file tmp-file))))
2778 ;;;###autoload
2779 (defun org-export-as-org (arg &optional hidden ext-plist
2780 to-buffer body-only pub-dir)
2781 "Make a copy with not-exporting stuff removed.
2782 The purpose of this function is to provide a way to export the source
2783 Org file of a webpage in Org format, but with sensitive and/or irrelevant
2784 stuff removed. This command will remove the following:
2786 - archived trees (if the variable `org-export-with-archived-trees' is nil)
2787 - comment blocks and trees starting with the COMMENT keyword
2788 - only trees that are consistent with `org-export-select-tags'
2789 and `org-export-exclude-tags'.
2791 The only arguments that will be used are EXT-PLIST and PUB-DIR,
2792 all the others will be ignored (but are present so that the general
2793 mechanism to call publishing functions will work).
2795 EXT-PLIST is a property list with external parameters overriding
2796 org-mode's default settings, but still inferior to file-local
2797 settings. When PUB-DIR is set, use this as the publishing
2798 directory."
2799 (interactive "P")
2800 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2801 ext-plist
2802 (org-infile-export-plist)))
2803 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2804 (filename (concat (file-name-as-directory
2805 (or pub-dir
2806 (org-export-directory :org opt-plist)))
2807 (file-name-sans-extension
2808 (file-name-nondirectory bfname))
2809 ".org"))
2810 (filename (and filename
2811 (if (equal (file-truename filename)
2812 (file-truename bfname))
2813 (concat (file-name-sans-extension filename)
2814 "-source."
2815 (file-name-extension filename))
2816 filename)))
2817 (backup-inhibited t)
2818 (buffer (find-file-noselect filename))
2819 (region (buffer-string))
2820 str-ret)
2821 (save-excursion
2822 (switch-to-buffer buffer)
2823 (erase-buffer)
2824 (insert region)
2825 (let ((org-inhibit-startup t)) (org-mode))
2826 (org-install-letbind)
2828 ;; Get rid of archived trees
2829 (org-export-remove-archived-trees (plist-get opt-plist :archived-trees))
2831 ;; Remove comment environment and comment subtrees
2832 (org-export-remove-comment-blocks-and-subtrees)
2834 ;; Get rid of excluded trees
2835 (org-export-handle-export-tags (plist-get opt-plist :select-tags)
2836 (plist-get opt-plist :exclude-tags))
2838 (when (or (plist-get opt-plist :plain-source)
2839 (not (or (plist-get opt-plist :plain-source)
2840 (plist-get opt-plist :htmlized-source))))
2841 ;; Either nothing special is requested (default call)
2842 ;; or the plain source is explicitly requested
2843 ;; so: save it
2844 (save-buffer))
2845 (when (plist-get opt-plist :htmlized-source)
2846 ;; Make the htmlized version
2847 (require 'htmlize)
2848 (require 'org-html)
2849 (font-lock-fontify-buffer)
2850 (let* ((htmlize-output-type 'css)
2851 (newbuf (htmlize-buffer)))
2852 (with-current-buffer newbuf
2853 (when org-export-htmlized-org-css-url
2854 (goto-char (point-min))
2855 (and (re-search-forward
2856 "<style type=\"text/css\">[^\000]*?\n[ \t]*</style>.*"
2857 nil t)
2858 (replace-match
2859 (format
2860 "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">"
2861 org-export-htmlized-org-css-url)
2862 t t)))
2863 (write-file (concat filename ".html")))
2864 (kill-buffer newbuf)))
2865 (set-buffer-modified-p nil)
2866 (if (equal to-buffer 'string)
2867 (progn (setq str-ret (buffer-string))
2868 (kill-buffer (current-buffer))
2869 str-ret)
2870 (kill-buffer (current-buffer))))))
2872 (defvar org-archive-location) ;; gets loaded with the org-archive require.
2873 (defun org-get-current-options ()
2874 "Return a string with current options as keyword options.
2875 Does include HTML export options as well as TODO and CATEGORY stuff."
2876 (require 'org-archive)
2877 (format
2878 "#+TITLE: %s
2879 #+AUTHOR: %s
2880 #+EMAIL: %s
2881 #+DATE: %s
2882 #+DESCRIPTION:
2883 #+KEYWORDS:
2884 #+LANGUAGE: %s
2885 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s
2886 #+OPTIONS: TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
2888 #+EXPORT_SELECT_TAGS: %s
2889 #+EXPORT_EXCLUDE_TAGS: %s
2890 #+LINK_UP: %s
2891 #+LINK_HOME: %s
2892 #+XSLT:
2893 #+CATEGORY: %s
2894 #+SEQ_TODO: %s
2895 #+TYP_TODO: %s
2896 #+PRIORITIES: %c %c %c
2897 #+DRAWERS: %s
2898 #+STARTUP: %s %s %s %s %s
2899 #+TAGS: %s
2900 #+FILETAGS: %s
2901 #+ARCHIVE: %s
2902 #+LINK: %s
2904 (buffer-name) (user-full-name) user-mail-address
2905 (format-time-string (substring (car org-time-stamp-formats) 1 -1))
2906 org-export-default-language
2907 org-export-headline-levels
2908 org-export-with-section-numbers
2909 org-export-with-toc
2910 org-export-preserve-breaks
2911 org-export-html-expand
2912 org-export-with-fixed-width
2913 org-export-with-tables
2914 org-export-with-sub-superscripts
2915 org-export-with-special-strings
2916 org-export-with-footnotes
2917 org-export-with-emphasize
2918 org-export-with-timestamps
2919 org-export-with-TeX-macros
2920 org-export-with-LaTeX-fragments
2921 org-export-skip-text-before-1st-heading
2922 org-export-with-drawers
2923 org-export-with-todo-keywords
2924 org-export-with-priority
2925 org-export-with-tags
2926 (if (featurep 'org-jsinfo) (org-infojs-options-inbuffer-template) "")
2927 (mapconcat 'identity org-export-select-tags " ")
2928 (mapconcat 'identity org-export-exclude-tags " ")
2929 org-export-html-link-up
2930 org-export-html-link-home
2931 (or (ignore-errors
2932 (file-name-sans-extension
2933 (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
2934 "NOFILENAME")
2935 "TODO FEEDBACK VERIFY DONE"
2936 "Me Jason Marie DONE"
2937 org-highest-priority org-lowest-priority org-default-priority
2938 (mapconcat 'identity org-drawers " ")
2939 (cdr (assoc org-startup-folded
2940 '((nil . "showall") (t . "overview") (content . "content"))))
2941 (if org-odd-levels-only "odd" "oddeven")
2942 (if org-hide-leading-stars "hidestars" "showstars")
2943 (if org-startup-align-all-tables "align" "noalign")
2944 (cond ((eq org-log-done t) "logdone")
2945 ((equal org-log-done 'note) "lognotedone")
2946 ((not org-log-done) "nologdone"))
2947 (or (mapconcat (lambda (x)
2948 (cond
2949 ((equal :startgroup (car x)) "{")
2950 ((equal :endgroup (car x)) "}")
2951 ((equal :newline (car x)) "")
2952 ((cdr x) (format "%s(%c)" (car x) (cdr x)))
2953 (t (car x))))
2954 (or org-tag-alist (org-get-buffer-tags)) " ") "")
2955 (mapconcat 'identity org-file-tags " ")
2956 org-archive-location
2957 "org file:~/org/%s.org"
2960 ;;;###autoload
2961 (defun org-insert-export-options-template ()
2962 "Insert into the buffer a template with information for exporting."
2963 (interactive)
2964 (if (not (bolp)) (newline))
2965 (let ((s (org-get-current-options)))
2966 (and (string-match "#\\+CATEGORY" s)
2967 (setq s (substring s 0 (match-beginning 0))))
2968 (insert s)))
2970 (defvar org-table-colgroup-info nil)
2972 (defun org-table-clean-before-export (lines &optional maybe-quoted)
2973 "Check if the table has a marking column.
2974 If yes remove the column and the special lines."
2975 (setq org-table-colgroup-info nil)
2976 (if (memq nil
2977 (mapcar
2978 (lambda (x) (or (string-match "^[ \t]*|-" x)
2979 (string-match
2980 (if maybe-quoted
2981 "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|"
2982 "^[ \t]*| *\\([\#!$*_^ /]\\) *|")
2983 x)))
2984 lines))
2985 ;; No special marking column
2986 (progn
2987 (setq org-table-clean-did-remove-column nil)
2988 (delq nil
2989 (mapcar
2990 (lambda (x)
2991 (cond
2992 ((org-table-colgroup-line-p x)
2993 ;; This line contains colgroup info, extract it
2994 ;; and then discard the line
2995 (setq org-table-colgroup-info
2996 (mapcar (lambda (x)
2997 (cond ((member x '("<" "&lt;")) :start)
2998 ((member x '(">" "&gt;")) :end)
2999 ((member x '("<>" "&lt;&gt;")) :startend)
3000 (t nil)))
3001 (org-split-string x "[ \t]*|[ \t]*")))
3002 nil)
3003 ((org-table-cookie-line-p x)
3004 ;; This line contains formatting cookies, discard it
3005 nil)
3006 (t x)))
3007 lines)))
3008 ;; there is a special marking column
3009 (setq org-table-clean-did-remove-column t)
3010 (delq nil
3011 (mapcar
3012 (lambda (x)
3013 (cond
3014 ((org-table-colgroup-line-p x)
3015 ;; This line contains colgroup info, extract it
3016 ;; and then discard the line
3017 (setq org-table-colgroup-info
3018 (mapcar (lambda (x)
3019 (cond ((member x '("<" "&lt;")) :start)
3020 ((member x '(">" "&gt;")) :end)
3021 ((member x '("<>" "&lt;&gt;")) :startend)
3022 (t nil)))
3023 (cdr (org-split-string x "[ \t]*|[ \t]*"))))
3024 nil)
3025 ((org-table-cookie-line-p x)
3026 ;; This line contains formatting cookies, discard it
3027 nil)
3028 ((string-match "^[ \t]*| *[!_^/] *|" x)
3029 ;; ignore this line
3030 nil)
3031 ((or (string-match "^\\([ \t]*\\)|-+\\+" x)
3032 (string-match "^\\([ \t]*\\)|[^|]*|" x))
3033 ;; remove the first column
3034 (replace-match "\\1|" t nil x))))
3035 lines))))
3037 (defun org-export-cleanup-toc-line (s)
3038 "Remove tags and timestamps from lines going into the toc."
3039 (when (memq org-export-with-tags '(not-in-toc nil))
3040 (if (string-match (org-re " +:[[:alnum:]_@#%:]+: *$") s)
3041 (setq s (replace-match "" t t s))))
3042 (when org-export-remove-timestamps-from-toc
3043 (while (string-match org-maybe-keyword-time-regexp s)
3044 (setq s (replace-match "" t t s))))
3045 (while (string-match org-bracket-link-regexp s)
3046 (setq s (replace-match (match-string (if (match-end 3) 3 1) s)
3047 t t s)))
3048 (while (string-match "\\[\\([0-9]\\|fn:[^]]*\\)\\]" s)
3049 (setq s (replace-match "" t t s)))
3053 (defun org-get-text-property-any (pos prop &optional object)
3054 (or (get-text-property pos prop object)
3055 (and (setq pos (next-single-property-change pos prop object))
3056 (get-text-property pos prop object))))
3058 (defun org-export-get-coderef-format (path desc)
3059 (save-match-data
3060 (if (and desc (string-match
3061 (regexp-quote (concat "(" path ")"))
3062 desc))
3063 (replace-match "%s" t t desc)
3064 (or desc "%s"))))
3066 (defun org-export-push-to-kill-ring (format)
3067 "Push buffer content to kill ring.
3068 The depends on the variable `org-export-copy-to-kill'."
3069 (when org-export-copy-to-kill-ring
3070 (org-kill-new (buffer-string))
3071 (when (fboundp 'x-set-selection)
3072 (ignore-errors (x-set-selection 'PRIMARY (buffer-string)))
3073 (ignore-errors (x-set-selection 'CLIPBOARD (buffer-string))))
3074 (message "%s export done, pushed to kill ring and clipboard" format)))
3076 (provide 'org-exp)
3078 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
3080 ;;; org-exp.el ends here