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