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