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