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