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